namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;

/// <summary>
/// Battle Bond is an ability exclusive to Greninja. When Greninja with this ability knocks out a Pokémon, it transforms into Ash-Greninja.
/// In its Ash-Greninja form, Water Shuriken's base power is increased to 20 and it always hits 3 times.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Battle_Bond_(Ability)">Bulbapedia - Battle Bond</see>
/// </summary>
[Script(ScriptCategory.Ability, "battle_bond")]
public class BattleBond : Script, IScriptChangeNumberOfHits, IScriptOnOpponentFaints, IScriptChangeBasePower
{
    /// <inheritdoc />
    public void OnOpponentFaints(IExecutingMove move, IPokemon target, byte hit)
    {
        if (move.User.Species.Name == "greninja" && move.User.Form.Name != "ash" &&
            move.User.Species.TryGetForm("ash", out var ashForm))
        {
            move.User.BattleData?.Battle.EventHook.Invoke(new AbilityTriggerEvent(move.User));
            move.User.ChangeForm(ashForm);
        }
    }

    /// <inheritdoc />
    public void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower)
    {
        if (move.UseMove.Name == "water_shuriken" && move.User.Form.Name == "ash")
            basePower = 20;
    }

    /// <inheritdoc />
    public void ChangeNumberOfHits(IMoveChoice choice, ref byte numberOfHits)
    {
        if (choice.ChosenMove.MoveData.Name == "water_shuriken" && choice.User.Form.Name == "ash")
        {
            numberOfHits = 3;
        }
    }
}