namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "set_status")]
public class SetStatus : Script, IScriptOnInitialize, IScriptOnSecondaryEffect
{
    private string? _status;

    /// <inheritdoc />
    public void OnInitialize(IReadOnlyDictionary<StringKey, object?>? parameters)
    {
        if (parameters?.TryGetValue("status", out var s) != true)
            throw new Exception("Missing required parameter 'status'");
        _status = s as string ?? throw new Exception("Missing required parameter 'status'");
    }

    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        if (_status == null)
            throw new Exception("Missing required parameter 'status'");
        target.SetStatus(_status, move.User);
    }
}