using System;
using PkmnLibSharp.Library;
using PkmnLibSharp.Utilities;

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


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