using System.Collections.Generic;
using Assets.Data;
using TMPro;
using UnityEngine;

public class TraitSelectorManager : MonoBehaviour
{
    [SerializeField]
    private TMP_InputField _compositionSize;

    [SerializeField]
    private ChampionSelector _championSelector;

    [SerializeField]
    private UIToLogic _emblemSelector;

    [SerializeField]
    private int _traitThreshold = 7;

    private Dictionary<TraitsEnum, int> emblemList;
    
    public void ListAllActivableCompo()
    {
        emblemList = _emblemSelector.GetEmblems();
        var champList = _championSelector.GetSelectedChampions();
        int compositionSize = _compositionSize.text == "" ? 1 : int.Parse(_compositionSize.text);
        var coroutine = StartCoroutine(TraitsMapping.GetChampionSubsetsAsync(champList, compositionSize,emblemList, HandleCombination));

    }

    private void HandleCombination(HashSet<ChampionsEnum> combination)
    {
        var synergies = TraitsMapping.MergeEmblems(
                TraitsMapping.TraitCountInCompo(combination),
                emblemList
            );
            var activeSynergies = TraitsMapping.FilterActiveTraits(synergies);
            if (activeSynergies.Count >= _traitThreshold)
            {
                var s = TraitsMapping.CompositionToString(combination, activeSynergies);
                Debug.Log(s);
            } else {
                Debug.LogWarning("Combination not valid");
            }            
    }
}
