using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Continuity.Content.Items;

namespace Continuity.Content.Systems
{
    public class EndgameRecipeOverrides : ModSystem
    {
        public override void AddRecipes() {
            for (int i = 0; i < Recipe.numRecipes; i++) {
		            Recipe recipe = Main.recipe[i];

		            if (recipe.TryGetResult(ItemID.Zenith, out Item _)) {
                    recipe.RemoveIngredient(ItemID.CopperShortsword);
                    recipe.RemoveIngredient(ItemID.BeeKeeper);
                    recipe.RemoveIngredient(ItemID.EnchantedSword);
		            }
                else if (recipe.TryGetResult(ItemID.EnchantedSword, out Item _)) {
                    recipe.AddIngredient(ItemID.CopperShortsword, 1);
		            }
                else if (recipe.TryGetResult(ItemID.TerraBlade, out Item _)) {
                    recipe.AddIngredient(ItemID.EnchantedSword, 1);
		            }
                // Calamity Endgame
                else if (ModLoader.TryGetMod("CalamityMod", out Mod calamityMod) && (calamityMod.TryFind<ModItem>("DragonPow", out ModItem dragonPow))) {
                    if (recipe.TryGetResult(dragonPow.Type, out Item _)) {
                        recipe.RemoveIngredient(ItemID.DaoofPow);
                    }
	              }
	          }
        }
    }
}
