using PkmnLib.Dynamic.Models;
using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Plugin.Gen7.Common;
using PkmnLib.Plugin.Gen7.Scripts.Abilities;
using PkmnLib.Plugin.Gen7.Scripts.Moves;
using PkmnLib.Static;
using PkmnLib.Static.Moves;
using PkmnLib.Static.Utils;

namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Abilities;

public class MegaLauncherTests
{
    [Test]
    public async Task ChangeHealPercent_HealPercentIncreasesForAuraMoves()
    {
        // Arrange
        var move = Substitute.For<IExecutingMove>();
        var target = Substitute.For<IPokemon>();
        var healPercent = 0.5f;
        var user = Substitute.For<IPokemon>();
        move.User.Returns(user);
        move.UseMove.Category.Returns(MoveCategory.Special);
        move.UseMove.HasFlag(MoveFlags.Pulse).Returns(true);
        var megaLauncher = new ScriptContainer(new MegaLauncher());
        move.User.AbilityScript.Returns(megaLauncher);
        move.GetScripts().Returns(new ScriptIterator([megaLauncher]));
        var healPercentScript = new HealPercent();
        uint healedAmount = 0;
        target.Heal(Arg.Do<uint>(amount => healedAmount = amount));
        target.BoostedStats.Returns(new StatisticSet<uint>(100, 100, 100, 100, 100, 100));

        // Act
        healPercentScript.OnInitialize(new Dictionary<StringKey, object?>
        {
            { "healPercent", healPercent },
        });
        healPercentScript.OnSecondaryEffect(move, target, 0);

        // Assert
        await Assert.That(healedAmount).IsEqualTo((uint)(target.BoostedStats.Hp * healPercent * 1.5f));
    }
}