using System;
using Pkmnlib;
using PkmnLibSharp.Utilities;

namespace PkmnLibSharp.Library
{
    public enum EffectParameterType
    {
        None = 0,
        Bool = 1,
        Int = 2,
        Float = 3,
        String = 4,
    }
    
    public class EffectParameter : PointerWrapper
    {
        public EffectParameter(string s) : base(Creatureliblibrary.Generated.EffectParameter.FromString(s.ToPtr()))
        {
        }

        public EffectParameter(bool b) : base(Creatureliblibrary.Generated.EffectParameter.FromBool(b.ToNative()))
        {
        }

        public EffectParameter(long l) : base(Creatureliblibrary.Generated.EffectParameter.FromInt(l))
        {
        }

        public EffectParameter(float f) : base(Creatureliblibrary.Generated.EffectParameter.FromFloat(f))
        {
        }

        public EffectParameterType ParameterType =>
            (EffectParameterType) Creatureliblibrary.Generated.EffectParameter.GetType(Ptr);

        public bool AsBool()
        {
            byte b = 0;
            Creatureliblibrary.Generated.EffectParameter.AsBool(Ptr, ref b).Assert();
            return b == 1;
        }
        
        public long AsInt()
        {
            long i = 0;
            Creatureliblibrary.Generated.EffectParameter.AsInt(Ptr, ref i).Assert();
            return i;
        }

        public float AsFloat()
        {
            float f = 0;
            Creatureliblibrary.Generated.EffectParameter.AsFloat(Ptr, ref f).Assert();
            return f;
        }

        public string AsString()
        {
            IntPtr p = IntPtr.Zero;
            Creatureliblibrary.Generated.EffectParameter.AsString(Ptr, ref p).Assert();
            return p.PtrString();
        }


        protected override void DeletePtr()
        {
            Creatureliblibrary.Generated.EffectParameter.Destruct(Ptr);
        }
    }
}