using System;
using PkmnLibSharp.Utilities;

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

        public Pokemon NewPokemon
        {
            get
            {
                if (_newPokemon != null) return _newPokemon;
                var ptr = Creaturelib.Generated.SwitchEvent.GetNewCreature(Ptr);
                if (TryResolvePointer(ptr, out _newPokemon))
                    return _newPokemon!;
                _newPokemon = Constructor.Active.ConstructPokemon(ptr)!;
                return _newPokemon;
            }
        }

        public byte Side => Creaturelib.Generated.SwitchEvent.GetSide(Ptr);
        public byte Index => Creaturelib.Generated.SwitchEvent.GetIndex(Ptr);


        private Pokemon? _newPokemon;

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