using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;

namespace Assets.Data
{
    [TestFixture]
    public class TestTraitsUtils
    {
        [Test]
        [TestCaseSource(typeof(BinaryCases), "EmblemsSynergies")]
        public void TestMergeEmblems(
            Dictionary<TraitsEnum, int> emblem,
            Dictionary<TraitsEnum, int> synergies,
            Dictionary<TraitsEnum, int> expected
        )
        {
            var output = TraitsMapping.MergeEmblems(emblem, synergies);
            foreach (KeyValuePair<TraitsEnum, int> pair in expected)
            {
                Assert.IsTrue(output[pair.Key] == pair.Value);
            }
        }

        [Test]
        [TestCaseSource(typeof(BinaryCases), "ActiveTraits")]
        public void TestActiveSynergyFilter(
            Dictionary<TraitsEnum, int> synergies,
            HashSet<TraitsEnum> expected
        )
        {
            var output = TraitsMapping.FilterActiveTraits(synergies);
            foreach (TraitsEnum trait in expected)
            {
                Assert.IsTrue(expected.Contains(trait));
            }

            foreach (TraitsEnum trait in output)
            {
                Assert.IsTrue(output.Contains(trait));
            }
        }

        [Test]
        public void TestMapping()
        {
            foreach (var champTraits in TraitsMapping.ChampsTraits)
            {
                foreach (var trait in champTraits.Value)
                {
                    Assert.IsTrue(TraitsMapping.TraitsChamp[trait].Contains(champTraits.Key));
                }
            }

            foreach (var traitChamps in TraitsMapping.TraitsChamp)
            {
                foreach (var champ in traitChamps.Value)
                {
                    Assert.IsTrue(TraitsMapping.ChampsTraits[champ].Contains(traitChamps.Key));
                }
            }
        }

        [Test]
        [TestCaseSource(typeof(BinaryCases), "con")]
        public void TestChampionCombination(HashSet<ChampionsEnum> champList, int compositionSize, int expectedCombinationCount)
        {
            var combination = TraitsMapping.GetChampionSubsets(champList, compositionSize);
            Assert.IsTrue(combination.Count == expectedCombinationCount);
        }
    }

    public class BinaryCases
    {
        public static IEnumerable EmblemsSynergies
        {
            get
            {
                yield return new TestCaseData(
                    new Dictionary<TraitsEnum, int> { { TraitsEnum.ARCANA, 1 } },
                    new Dictionary<TraitsEnum, int> { { TraitsEnum.ARCANA, 1 } },
                    new Dictionary<TraitsEnum, int> { { TraitsEnum.ARCANA, 2 } }
                );
                yield return new TestCaseData(
                    new Dictionary<TraitsEnum, int>
                    {
                        { TraitsEnum.ARCANA, 1 },
                        { TraitsEnum.DRAGON, 2 },
                        { TraitsEnum.FROST, 3 },
                        { TraitsEnum.HONEYMANCY, 4 },
                        { TraitsEnum.PYRO, 5 },
                        { TraitsEnum.WARRIOR, 6 },
                    },
                    new Dictionary<TraitsEnum, int>
                    {
                        { TraitsEnum.ARCANA, 1 },
                        { TraitsEnum.DRAGON, 2 },
                        { TraitsEnum.FROST, 3 },
                        { TraitsEnum.HONEYMANCY, 4 },
                        { TraitsEnum.PYRO, 5 },
                        { TraitsEnum.WARRIOR, 6 },
                    },
                    new Dictionary<TraitsEnum, int>
                    {
                        { TraitsEnum.ARCANA, 2 },
                        { TraitsEnum.DRAGON, 4 },
                        { TraitsEnum.FROST, 6 },
                        { TraitsEnum.HONEYMANCY, 8 },
                        { TraitsEnum.PYRO, 10 },
                        { TraitsEnum.WARRIOR, 12 },
                    }
                );
                /*
                here is the list of traits :
                    ARCANA,
        CHRONO,
        DRAGON,
        DRUID,
        ELDRICHT,
        FAERIE,
        FROST,
        HONEYMANCY,
        PORTAL,
        PYRO,
        SUGARCRAFT,
        WITCHCRAFT,
        BASTION,
        BLASTER,
        HUNTER,
        INCANTATOR,
        MAGE,
        MULTISTRIKER,
        PRESERVER,
        SCHOLAR,
        SHAPESHIFTER,
        VANGUARD,
        WARRIOR
    
                */
            }
        }

        public static IEnumerable ActiveTraits
        {
            get
            {
                yield return new TestCaseData(
                    new Dictionary<TraitsEnum, int>
                    {
                        { TraitsEnum.ARCANA, 1 },
                        { TraitsEnum.DRAGON, 2 },
                        { TraitsEnum.FROST, 3 },
                        { TraitsEnum.HONEYMANCY, 4 },
                        { TraitsEnum.PYRO, 1 },
                        { TraitsEnum.WARRIOR, 1 },
                    },
                    new HashSet<TraitsEnum>
                    {
                        TraitsEnum.DRAGON,
                        TraitsEnum.FROST,
                        TraitsEnum.HONEYMANCY,
                        TraitsEnum.PYRO,
                    }
                );

                yield return new TestCaseData(
                    new Dictionary<TraitsEnum, int>
                    {
                        { TraitsEnum.ARCANA, 5 },
                        { TraitsEnum.FROST, 2 },
                        { TraitsEnum.HONEYMANCY, 7 },
                        { TraitsEnum.PYRO, 4 },
                        { TraitsEnum.WARRIOR, 3 },
                    },
                    new HashSet<TraitsEnum>
                    {
                        TraitsEnum.ARCANA,
                        TraitsEnum.HONEYMANCY,
                        TraitsEnum.PYRO,
                        TraitsEnum.WARRIOR,
                    }
                );
            }
        }
    }
}
