namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "judgement")]
public class Judgement : Script, IScriptChangeMoveType
{
    /// <inheritdoc />
    public void ChangeMoveType(IExecutingMove move, IPokemon target, byte hit, ref TypeIdentifier? moveType)
    {
        var heldItem = move.User.HeldItem;
        if (heldItem == null)
            return;
        var typeLibrary = target.Library.StaticLibrary.Types;

        moveType = heldItem.Name.ToString().ToLowerInvariant() switch
        {
            "dread_plate" when typeLibrary.TryGetTypeIdentifier("dark", out var dark) => dark,
            "earth_plate" when typeLibrary.TryGetTypeIdentifier("ground", out var ground) => ground,
            "fist_plate" when typeLibrary.TryGetTypeIdentifier("fighting", out var fighting) => fighting,
            "flame_plate" when typeLibrary.TryGetTypeIdentifier("fire", out var fire) => fire,
            "icicle_plate" when typeLibrary.TryGetTypeIdentifier("ice", out var ice) => ice,
            "insect_plate" when typeLibrary.TryGetTypeIdentifier("bug", out var bug) => bug,
            "iron_plate" when typeLibrary.TryGetTypeIdentifier("steel", out var steel) => steel,
            "meadow_plate" when typeLibrary.TryGetTypeIdentifier("grass", out var grass) => grass,
            "mind_plate" when typeLibrary.TryGetTypeIdentifier("psychic", out var psychic) => psychic,
            "pixie_plate" when typeLibrary.TryGetTypeIdentifier("fairy", out var fairy) => fairy,
            "sky_plate" when typeLibrary.TryGetTypeIdentifier("flying", out var flying) => flying,
            "spooky_plate" when typeLibrary.TryGetTypeIdentifier("ghost", out var ghost) => ghost,
            "stone_plate" when typeLibrary.TryGetTypeIdentifier("rock", out var rock) => rock,
            "toxic_plate" when typeLibrary.TryGetTypeIdentifier("poison", out var poison) => poison,
            "zap_plate" when typeLibrary.TryGetTypeIdentifier("electric", out var electric) => electric,
            "draco_plate" when typeLibrary.TryGetTypeIdentifier("dragon", out var dragon) => dragon,
            "splash_plate" when typeLibrary.TryGetTypeIdentifier("water", out var water) => water,
            _ => moveType,
        };
    }
}