using PkmnLib.Plugin.Gen7.Scripts.Status;

namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "rest")]
public class Rest : Script, IScriptOnSecondaryEffect
{
    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        if (move.User.HasStatus(ScriptUtils.ResolveName<Sleep>()))
        {
            move.GetHitData(target, hit).Fail();
            return;
        }
        if (!move.User.Heal(move.User.MaxHealth))
        {
            move.GetHitData(target, hit).Fail();
            return;
        }
        if (move.User.ActiveAbility?.Effect == ScriptUtils.ResolveName<Abilities.InnerFocus>())
        {
            move.GetHitData(target, hit).Fail();
            return;
        }

        if (move.User.SetStatus(ScriptUtils.ResolveName<Sleep>(), move.User) &&
            move.User.StatusScript.Script is Sleep sleep)
            sleep.Turns = 2;
    }
}