namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "weather_ball")]
public class WeatherBall : Script, IScriptChangeMoveType, IScriptChangeBasePower
{
    /// <inheritdoc />
    public void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower)
    {
        if (move.Battle.WeatherName is not null)
        {
            basePower = basePower.MultiplyOrMax(2);
        }
    }

    /// <inheritdoc />
    public void ChangeMoveType(IExecutingMove move, IPokemon target, byte hit, ref TypeIdentifier? typeIdentifier)
    {
        var weather = move.Battle.WeatherName;
        var typeLibrary = move.Battle.Library.StaticLibrary.Types;
        if (weather is null)
            return;

        if (weather == ScriptUtils.ResolveName<Weather.HarshSunlight>() &&
            typeLibrary.TryGetTypeIdentifier("fire", out var fireType))
            typeIdentifier = fireType;
        else if (weather == ScriptUtils.ResolveName<Weather.Rain>() &&
                 typeLibrary.TryGetTypeIdentifier("water", out var waterType))
            typeIdentifier = waterType;
        else if (weather == ScriptUtils.ResolveName<Weather.Hail>() &&
                 typeLibrary.TryGetTypeIdentifier("ice", out var iceType))
            typeIdentifier = iceType;
        else if (weather == ScriptUtils.ResolveName<Weather.Sandstorm>() &&
                 typeLibrary.TryGetTypeIdentifier("rock", out var rockType))
            typeIdentifier = rockType;
    }
}