require 'Scripts/safe_load.lua'

function parseAchievement(achievementDefinition)
    local achievement = AchievementData:create();

    achievement:setEventTrackerType(achievementDefinition.eventTrackerType);
    achievement:setGameEventType(achievementDefinition.gameEventType);
    achievement:setThreshold(achievementDefinition.threshold);

    if achievementDefinition.achievementIdAmazonGameCircle ~= nil then
        achievement:setAchievementIdAmazonGameCircle(achievementDefinition.achievementIdAmazonGameCircle);
    end

    if achievementDefinition.achievementIdBlackBerry ~= nil then
        achievement:setAchievementIdBlackBerry(achievementDefinition.achievementIdBlackBerry);
    end

    if achievementDefinition.achievementIdGooglePlay ~= nil then
        achievement:setAchievementIdGooglePlay(achievementDefinition.achievementIdGooglePlay);
    end

    if achievementDefinition.achievementIdIOS ~= nil then
        achievement:setAchievementIdIOS(achievementDefinition.achievementIdIOS);
    end
    
    if achievementDefinition.achievementIdSteam ~= nil then
        achievement:setAchievementIdSteam(achievementDefinition.achievementIdSteam);
    end

    if achievementDefinition.achievementIdWindowsPhone ~= nil then
        achievement:setAchievementIdWindowsPhone(achievementDefinition.achievementIdWindowsPhone);
    end

    return achievement;
end

local achievements = CCArray:create();

local achievementDefinitions = loadFileSafe("Scripts/Data/achievements.lua",
    {
        EventTrackerType_Counter=EventTrackerType_Counter,
        EventTrackerType_Threshold=EventTrackerType_Threshold,

        GameEventType_AchievementsUnlocked=GameEventType_AchievementsUnlocked,
        GameEventType_BoosterSmash=GameEventType_BoosterSmash,
        GameEventType_BoosterUpgradePurchase=GameEventType_BoosterUpgradePurchase,
        GameEventType_CoinCollection=GameEventType_CoinCollection,
        GameEventType_Dodge=GameEventType_Dodge,
        GameEventType_HeroMaxMultiplier=GameEventType_HeroMaxMultiplier,
        GameEventType_HeroMaxScore=GameEventType_HeroMaxScore,
        GameEventType_LevelCleared=GameEventType_LevelCleared,
        GameEventType_LifeRefillPurchase=GameEventType_LifeRefillPurchase,
        GameEventType_NeighbourhoodsCompleted=GameEventType_NeighbourhoodsCompleted,
        GameEventType_OneSecondRemaining=GameEventType_OneSecondRemaining,
        GameEventType_OrbitalPunchTruck=GameEventType_OrbitalPunchTruck,
        GameEventType_PropDestroyed=GameEventType_PropDestroyed,
        GameEventType_PropThrowKill=GameEventType_PropThrowKill,
        GameEventType_Punch=GameEventType_Punch,
        GameEventType_RevivePurchase=GameEventType_RevivePurchase,
        GameEventType_SinglePunchKill=GameEventType_SinglePunchKill,
        GameEventType_SpecialAttack=GameEventType_SpecialAttack,
        GameEventType_SpecialAttackPurchase=GameEventType_SpecialAttackPurchase,
        GameEventType_SpecialUpgradePurchase=GameEventType_SpecialUpgradePurchase,
        GameEventType_StatUpgradePurchase=GameEventType_StatUpgradePurchase,
        GameEventType_Throw=GameEventType_Throw,
        GameEventType_TutorialShow=GameEventType_TutorialShow,
        GameEventType_Uppercut=GameEventType_Uppercut,
    }
);

for key, achievementDefinition in pairs(achievementDefinitions) do
    achievements:addObject(parseAchievement(achievementDefinition));
end

return achievements;