namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;

/// <summary>
/// Multitype is an ability that changes the Pokémon's type based on its held Plate or Z-Crystal.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Multitype_(Ability)">Bulbapedia - Multitype</see>
/// </summary>
[Script(ScriptCategory.Ability, "multitype")]
public class Multitype : Script, IScriptOnAfterHeldItemChange
{
    /// <inheritdoc />
    public void OnAfterHeldItemChange(IPokemon pokemon, IItem? previous, IItem? item)
    {
        if (pokemon.Species.Name != "arceus")
            return;
        if (item is null && pokemon.Form.Name != "default")
        {
            pokemon.ChangeForm(pokemon.Species.GetDefaultForm());
        }
        else if (item is not null && item.Name.ToString().EndsWith("_plate", StringComparison.OrdinalIgnoreCase))
        {
            var platePrefix = item.Name.ToString().Replace("_plate", string.Empty, StringComparison.OrdinalIgnoreCase);
            switch (platePrefix)
            {
                case "fist" when pokemon.Species.TryGetForm("arceus_fighting", out var fightingForm):
                    pokemon.ChangeForm(fightingForm);
                    break;
                case "flame" when pokemon.Species.TryGetForm("arceus_fire", out var fireForm):
                    pokemon.ChangeForm(fireForm);
                    break;
                case "shock" when pokemon.Species.TryGetForm("arceus_electric", out var electricForm):
                    pokemon.ChangeForm(electricForm);
                    break;
                case "draco" when pokemon.Species.TryGetForm("arceus_dragon", out var dragonForm):
                    pokemon.ChangeForm(dragonForm);
                    break;
                case "dread" when pokemon.Species.TryGetForm("arceus_dark", out var darkForm):
                    pokemon.ChangeForm(darkForm);
                    break;
                case "earth" when pokemon.Species.TryGetForm("arceus_ground", out var groundForm):
                    pokemon.ChangeForm(groundForm);
                    break;
                case "icicle" when pokemon.Species.TryGetForm("arceus_ice", out var iceForm):
                    pokemon.ChangeForm(iceForm);
                    break;
                case "insect" when pokemon.Species.TryGetForm("arceus_bug", out var bugForm):
                    pokemon.ChangeForm(bugForm);
                    break;
                case "iron" when pokemon.Species.TryGetForm("arceus_steel", out var steelForm):
                    pokemon.ChangeForm(steelForm);
                    break;
                case "meadow" when pokemon.Species.TryGetForm("arceus_grass", out var grassForm):
                    pokemon.ChangeForm(grassForm);
                    break;
                case "mind" when pokemon.Species.TryGetForm("arceus_psychic", out var psychicForm):
                    pokemon.ChangeForm(psychicForm);
                    break;
                case "pixie" when pokemon.Species.TryGetForm("arceus_fairy", out var fairyForm):
                    pokemon.ChangeForm(fairyForm);
                    break;
                case "sky" when pokemon.Species.TryGetForm("arceus_flying", out var flyingForm):
                    pokemon.ChangeForm(flyingForm);
                    break;
                case "splash" when pokemon.Species.TryGetForm("arceus_water", out var waterForm):
                    pokemon.ChangeForm(waterForm);
                    break;
                case "spooky" when pokemon.Species.TryGetForm("arceus_ghost", out var ghostForm):
                    pokemon.ChangeForm(ghostForm);
                    break;
                case "stone" when pokemon.Species.TryGetForm("arceus_rock", out var rockForm):
                    pokemon.ChangeForm(rockForm);
                    break;
                case "toxic" when pokemon.Species.TryGetForm("arceus_poison", out var poisonForm):
                    pokemon.ChangeForm(poisonForm);
                    break;
            }
        }
    }
}