namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "conversion")]
public class Conversion : Script, IScriptOnSecondaryEffect
{
    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        var moveType = move.User.Moves.WhereNotNull().FirstOrDefault()?.MoveData.MoveType;
        if (moveType == null)
        {
            move.GetHitData(target, hit).Fail();
            return;
        }
        move.User.SetTypes([moveType.Value]);
    }
}