using PkmnLib.Static.Moves;

namespace PkmnLib.Plugin.Gen7.Scripts.Battle;

[Script(ScriptCategory.Battle, "wonder_room_effect")]
public class WonderRoomEffect : Script, IScriptChangeDefensiveStatValue, IScriptOnEndTurn
{
    public int TurnsLeft { get; private set; } = 5;

    /// <inheritdoc />
    public void ChangeDefensiveStatValue(IExecutingMove move, IPokemon target, byte hit, uint offensiveStat,
        ImmutableStatisticSet<uint> targetStats, Statistic stat, ref uint value)
    {
        value = move.UseMove.Category switch
        {
            MoveCategory.Special => targetStats.Defense,
            MoveCategory.Physical => targetStats.SpecialDefense,
            _ => value,
        };
    }

    /// <inheritdoc />
    public void OnEndTurn(IScriptSource owner, IBattle battle)
    {
        TurnsLeft--;
        if (TurnsLeft <= 0)
        {
            RemoveSelf();
        }
    }
}