#priority -99

import mods.ItemStages;
import mods.MobStages;
import mods.orestages.OreStages;
import mods.recipestages.Recipes;

import scripts.gamestages.classes.gamestage.GameStage;
import scripts.gamestages.stages.arcana_artificing;
import scripts.gamestages.stages.arcana_darkengineering;
import scripts.gamestages.stages.arcana_druidity;
import scripts.gamestages.stages.arcana_occultism;
import scripts.gamestages.stages.mastery_arcana;
import scripts.gamestages.stages.mastery_complete;
import scripts.gamestages.stages.mastery_profession;
import scripts.gamestages.stages.profession_adventuring;
import scripts.gamestages.stages.profession_agriculture;
import scripts.gamestages.stages.profession_engineering;

// ==================================
// Initialize Stages
initStaging();
initPackages();

// ==================================
// GameStage Object list
static packStages as GameStage[] = [
	arcana_artificing.initStage(),
	arcana_darkengineering.initStage(),
	arcana_druidity.initStage(),
	arcana_occultism.initStage(),
	mastery_arcana.initStage(),
	mastery_complete.initStage(),
	mastery_profession.initStage(),
	profession_adventuring.initStage(),
	profession_agriculture.initStage(),
	profession_engineering.initStage()
];

/**
 *  Package/Fake Player staging goes here. This will be run after all other staging.
 */
static packages as string[][string] = {
	"appeng": ["Engineering", "Farming", "Adventuring", "Druidity", "Artificing", "Occultism", "Dark_Engineering"],
    "thaumicenergistics": ["Engineering", "Artificing"],
	"thaumcraft": ["Artificing"],
	"crazypants.enderio": ["Engineering", "Dark_Engineering", "Occultism"],
    "blusunrize.immersiveengineering": ["Engineering", "Dark_Engineering"],
    "wile.engineersdecor": ["Engineering"],
	"vazkii.botania": ["Druidity"],
	"buzz135.industrial": ["Engineering", "Farming", "Adventuring", "Druidity", "Artificing", "Occultism", "Dark_Engineering"],
    "decivex.mech_crafting": ["Engineering", "Farming", "Adventuring", "Druidity", "Artificing", "Occultism", "Dark_Engineering"],
};

// ==================================
// Run Staging
function initStaging() as void {
    for stage in packStages {
        val stageName = stage.getName();

        //==================================
        // Mod Staging
        for modId in stage.getStagedMods() {
            if(loadedMods has modId) {
                //Iterating through mod items
                for item in loadedMods[modId].items {
                    var toStage = true;

                    for blacklistName in stage.getNamesBlacklist() {
                        //If item has blacklist name, it will be removed from the stage.
                        if(item.definition.id has blacklistName) {
                            toStage = false;
                        }

                        //If the item is aready set to be staged ignores whitelist.
                        if(!toStage) {
                            //Iterate through whitelist.
                            for whitelistName in stage.getNamesWhitelist() {
                                if(item.definition.id has whitelistName) {
                                    toStage = true;
                                    break;
                                }
                            }
                        }
                    }

                    if(toStage) {
                        for subItem in item.definition.subItems {
                            ItemStages.addItemStage(stageName, subItem);
                            Recipes.setRecipeStage(stageName, subItem);
                        }
                    }
                }
            }
        }

        //==================================
        // Item Staging
        for item in stage.getStagedItems() {
            ItemStages.addItemStage(stageName, item);
            Recipes.setRecipeStage(stageName, item);
        }


        //==================================
        // Item Staging
        for recipeName in stage.getStagedRecipeNames() {
            Recipes.setRecipeStage(stageName, recipeName);
        }

        //==================================
        // Mob Staging
        for mobId in stage.getStagedMobs() {
            MobStages.addStage(stageName, mobId);
        }

        //==================================
        // Enchant Staging
        for enchant in stage.getStagedEnchants() {
            ItemStages.stageEnchant(stageName, enchant);
        }

        //==================================
        // JEI Category Staging
        for category in stage.getStagedJeiCategories() {
            ItemStages.stageRecipeCategory(stageName, category);
        }
    }
}


function initPackages() as void {
    for package, stages in packages {
        Recipes.setPackageStage(package, stages);
    }
}
