using System;
using PkmnLibSharp.Utilities;

namespace PkmnLibSharp.Battling.Events
{
    public class ExperienceGainEvent : EventData
    {
        internal ExperienceGainEvent(EventDataKind kind, IntPtr ptr) : base(kind, ptr)
        {
        }
        
        public Pokemon Pokemon
        {
            get
            {
                if (_pokemon != null) return _pokemon;
                var ptr = Creaturelib.Generated.ExperienceGainEvent.GetCreature(Ptr);
                if (TryResolvePointer(ptr, out _pokemon))
                    return _pokemon!;
                _pokemon = Constructor.Active.ConstructPokemon(ptr)!;
                return _pokemon;
            }
        }

        private uint PreviousExperience => Creaturelib.Generated.ExperienceGainEvent.GetPreviousExperience(Ptr);
        private uint NewExperience => Creaturelib.Generated.ExperienceGainEvent.GetNewExperience(Ptr);
        
        
        private Pokemon? _pokemon;

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