using System;
using PkmnLibSharp.Utilities;

namespace PkmnLibSharp.Battling.Events
{
    public class HealEvent : EventData
    {
        internal HealEvent(EventDataKind kind, IntPtr ptr) : base(kind, ptr)
        {
        }

        public Pokemon Pokemon
        {
            get
            {
                if (_pokemon != null) return _pokemon;
                var ptr = Creaturelib.Generated.HealEvent.GetCreature(Ptr);
                if (TryResolvePointer(ptr, out _pokemon))
                    return _pokemon!;
                _pokemon = Constructor.Active.ConstructPokemon(ptr)!;
                return _pokemon;
            }
        }

        public uint OriginalHealth => Creaturelib.Generated.HealEvent.GetOriginalHealth(Ptr);
        public uint NewHealth => Creaturelib.Generated.HealEvent.GetNewHealth(Ptr);

        private Pokemon? _pokemon;

        protected override void DeletePtr()
        {
            Creaturelib.Generated.HealEvent.Destruct(Ptr);
        }
    }
}