using System;
using PkmnLibSharp.Utilities;

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

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

        public DamageSource Source => (DamageSource) Creaturelib.Generated.DamageEvent.GetDamageSource(Ptr);
        public uint OriginalHealth => Creaturelib.Generated.DamageEvent.GetOriginalHealth(Ptr);
        public uint NewHealth => Creaturelib.Generated.DamageEvent.GetNewHealth(Ptr);

        private Pokemon? _pokemon;

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