using PkmnLib.Plugin.Gen7.Scripts.Pokemon;

namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "curse")]
public class Curse : Script, IScriptOnSecondaryEffect
{
    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        var battleData = move.User.BattleData;
        if (battleData == null)
            return;
        var typeLibrary = battleData.Battle.Library.StaticLibrary.Types;
        if (!typeLibrary.TryGetTypeIdentifier("ghost", out var ghostType))
            return;
        if (move.User.Types.Contains(ghostType))
        {
            move.User.Damage(move.User.MaxHealth / 2, DamageSource.Misc, forceDamage: true);
            target.Volatile.Add(new GhostCurseEffect(target));
        }
        else
        {
            EventBatchId batchId = new();
            move.User.ChangeStatBoost(Statistic.Speed, -1, true, false, batchId);
            move.User.ChangeStatBoost(Statistic.Defense, 1, true, false, batchId);
            move.User.ChangeStatBoost(Statistic.Attack, 1, true, false, batchId);
        }
    }
}