using Jovian.TagSystem;
using NUnit.Framework;

namespace Jovian.TagSystem.Tests {
    public class TestGameTagUtility {
        private const string TagBase = "Test";
        private const string TagOne = "Test.One";
        private const string TagTwo = "Test.Two";
        private const string TagThree = "Test.Three";
        private const string TagFour = "Test.One.Four";

        [SetUp]
        public void Setup() {
            var tags = new RegisteredTag[] { new(TagOne), new(TagTwo), new(TagThree), new(TagFour), new(TagBase) };
            JovianTagsHandler.Initialize();
            JovianTagsHandler.RegisterTags(tags);
        }

        [Test]
        public void TestCreateGameTagContainer() {
            var selection = new JovianTagsGroup(TagOne, TagTwo, TagFour);
            var container = CreateGameTagContainer(selection);
            Assert.AreEqual(3, container.Count);
        }

        [Test]
        public void TestCreateGameTagContainerWithCapacity() {
            var selection = new JovianTagsGroup(TagOne, TagTwo, TagFour);
            var container = CreateGameTagContainer(selection, 10);
            Assert.AreEqual(3, container.Count);
            Assert.AreEqual(10, container.entries.Capacity);
        }

        [TearDown]
        public void PostTest() {
            JovianTagsHandler.Reset();
        }

        private JovianTagsContainer CreateGameTagContainer(JovianTagsGroup group) {
            return group.ToContainer();
        }

        private JovianTagsContainer CreateGameTagContainer(JovianTagsGroup group, int capacity) {
            if(!group.HasAny()) return JovianTagsContainer.Empty;
            var container = new JovianTagsContainer(capacity);
            foreach(var tag in group.tags) {
                var resolved = JovianTagsHandler.GetTag(tag);
                if(resolved.IsValid()) container.Add(resolved);
            }
            return container;
        }
    }
}
