namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "pain_split")]
public class PainSplit : Script, IScriptOnSecondaryEffect
{
    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        var userHp = move.User.CurrentHealth;
        var targetHp = target.CurrentHealth;
        var averageHp = (userHp + targetHp) / 2;
        var evtBatch = new EventBatchId();
        if (userHp > averageHp)
        {
            move.User.Damage(userHp - averageHp, DamageSource.Misc, evtBatch, true);
        }
        else if (userHp < averageHp)
        {
            move.User.Heal(averageHp - userHp, false, evtBatch, true);
        }
        if (targetHp > averageHp)
        {
            target.Damage(targetHp - averageHp, DamageSource.Misc, evtBatch, true);
        }
        else if (targetHp < averageHp)
        {
            target.Heal(averageHp - targetHp, false, evtBatch, true);
        }
    }
}