namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;

/// <summary>
/// Overcoat is an ability that protects the Pokémon from weather damage and powder moves.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Overcoat_(Ability)">Bulbapedia - Overcoat</see>
/// </summary>
[Script(ScriptCategory.Ability, "overcoat")]
public class Overcoat : Script, IScriptIsInvulnerableToMove, IScriptCustomTrigger
{
    /// <inheritdoc />
    public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
    {
        if (eventName == CustomTriggers.IgnoreHail && args is CustomTriggers.IgnoreHailArgs hailArgs)
        {
            hailArgs.Ignore = true;
        }
        else if (eventName == CustomTriggers.BypassSandstormDamage &&
                 args is CustomTriggers.BypassSandstormDamageArgs bypassArgs)
        {
            bypassArgs.Bypass = true;
        }
    }

    /// <inheritdoc />
    public void IsInvulnerableToMove(IExecutingMove move, IPokemon target, ref bool invulnerable)
    {
        if (move.UseMove.HasFlag(MoveFlags.Powder))
        {
            invulnerable = true;
        }
    }
}