using NUnit.Framework;
using PkmnLibSharp.Library;
using PkmnLibSharp.Library.Moves;
using PkmnLibSharp.Utilities;

namespace PkmnLibSharpTests.Library
{
    public class MoveLibraryTests
    {
        [Test]
        public void ConstructDestruct()
        {
            var item = new MoveLibrary(100);
            item.Dispose();
        }

        [Test]
        public void Insert()
        {
            var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
                0.5f, "test", new EffectParameter[0], new string[0]);
            var library = new MoveLibrary(100);
            library.Insert("foobar", move);
            Assert.AreEqual(1, library.Count);
            library.Dispose();
        }
        
        [Test]
        public void Delete()
        {
            var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
                0.5f, "test", new EffectParameter[0], new string[0]);
            var library = new MoveLibrary(100);
            library.Insert("foobar", move);
            Assert.AreEqual(1, library.Count);
            library.Delete("foobar");
            Assert.AreEqual(0, library.Count);
            library.Dispose();
        }
        
        [Test]
        public void Get()
        {
            var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
                0.5f, "test", new EffectParameter[0], new string[0]);
            var library = new MoveLibrary(100);
            library.Insert("foobar", move);
            Assert.AreEqual(1, library.Count);
            var m = library.Get("foobar");
            Assert.AreEqual(m.Name, "foobar");
            Assert.Throws<NativeException>(() =>
            {
                library.Get("barfoo");
            });
            library.Dispose();
        }
        
        [Test]
        public void TryGet()
        {
            var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
                0.5f, "test", new EffectParameter[0], new string[0]);
            var library = new MoveLibrary(100);
            library.Insert("foobar", move);
            Assert.AreEqual(1, library.Count);
            Assert.True(library.TryGet("foobar", out move));
            Assert.AreEqual(move.Name, "foobar");
            Assert.False(library.TryGet("barfoo", out move));
            library.Dispose();
        }

    }
}