using System;
using PkmnLibSharp.Utilities;

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

        private Pokemon? _pokemon;
        protected override void DeletePtr()
        {
            Creaturelib.Generated.MissEvent.Destruct(Ptr);
        }
    }
}