using PkmnLib.Plugin.Gen7.Scripts.Side;

namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "echoed_voice")]
public class EchoedVoice : Script, IScriptOnSecondaryEffect, IScriptChangeBasePower
{
    public void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower)
    {
        var battleData = move.User.BattleData;
        if (battleData == null)
            return;
        var side = battleData.Battle.Sides[battleData.SideIndex];
        var echoedVoiceData = side.VolatileScripts.Get<EchoedVoiceData>();
        if (echoedVoiceData == null)
            return;

        var newBasePower = basePower + (ushort)(echoedVoiceData.Stacks * 40);
        basePower = (ushort)Math.Min(newBasePower, 200);
    }

    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        var battleData = move.User.BattleData;
        if (battleData == null)
            return;
        var side = battleData.Battle.Sides[battleData.SideIndex];
        side.VolatileScripts.Add(new EchoedVoiceData());
    }
}