namespace PkmnLib.Plugin.Gen7.Scripts.Terrain;

[Script(ScriptCategory.Terrain, "electric_terrain")]
public class ElectricTerrain : Script, IScriptChangeBasePower, IScriptPreventStatusChange, IScriptPreventVolatileAdd
{
    private static bool IsAffectedByTerrain(IPokemon pokemon) =>
        !pokemon.IsFloating;

    /// <inheritdoc />
    public void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower)
    {
        if (!IsAffectedByTerrain(move.User))
            return;
        var type = move.GetHitData(target, hit).Type;
        if (type?.Name == "electric")
            basePower = basePower.MultiplyOrMax(1.5f);
    }

    /// <inheritdoc />
    public void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted, ref bool preventStatus)
    {
        if (!IsAffectedByTerrain(pokemon))
            return;
        if (status == ScriptUtils.ResolveName<Status.Sleep>())
            preventStatus = true;
    }

    /// <inheritdoc />
    public void PreventVolatileAdd(IScriptSource parent, Script script, ref bool preventVolatileAdd)
    {
        if (parent is IPokemon pokemon && !IsAffectedByTerrain(pokemon))
            return;

        if (script is Pokemon.YawnEffect)
            preventVolatileAdd = true;
    }
}