using System.Collections.Generic;
using System.Linq;
using GameMessage;

namespace GameFix.Poker
{
    /// <summary>
    /// 正510K
    /// </summary>
    public class CardStyle510KPlusHelper : CardStyle510KHelper
    {
        public override int CardStyle => DataCardConst.CardStyle510KPlus;
        
        internal override bool CheckStyleNormal(CardBaseGroup group, out CardStyleInfo cardStyleInfo)
        {
            var isRight = base.CheckStyleNormal(group, out cardStyleInfo);
            if (isRight)
                return group.Cards.Select(x => x.Suit).AllElementsSame();

            return false;
        }

        internal override bool CheckStyleWithLZ(CardBaseGroup group, out CardStyleInfo cardStyleInfo)
        {
            var isRight = base.CheckStyleNormal(group, out cardStyleInfo);
            if (isRight)
                return group.Cards.Select(x => x.Suit).AllElementsSame();

            return false;
        }

        internal override List<CardGroupList> GetAllEatTipGroup(CardBaseGroup group, CardStyleInfo eatStyleInfo)
        {// 只提示一个
            var groupList = new List<CardGroupList>(1);
            List<Card> cards = new List<Card>();
            foreach (var v in V_510K)
            {
                if (group.CardGroupList[v].Count > 0)
                    cards.AddRange(group.CardGroupList[v]);
            }
            // 按照花色分组
            var suitCardDict = cards.GroupBy(x => x.Suit)
                .ToDictionary(g => g.Key, g => g.Distinct(new CardValueEqualityComparer()).ToList());
            foreach (var suitCards in suitCardDict.Values)
            {
                if (suitCards.Count != CardCnt) continue;
                groupList.Add(new CardGroupList(suitCards));
                break;
            }
            
            
            return groupList;
        }

        internal override List<CardGroupList> GetAllEatTipGroupWithLZ(CardBaseGroup group, CardStyleInfo eatStyleInfo)
        {
            var groupList = new List<CardGroupList>(1);
            List<Card> cards = new List<Card>();
            foreach (var v in V_510K)
            {
                if (group.CardGroupList[v].Count > 0)
                    cards.AddRange(group.CardGroupList[v]);
            }
            // 按照花色分组
            var suitCardDict = cards.GroupBy(x => x.Suit)
                .ToDictionary(g => g.Key, g => g.Distinct().ToList());
            foreach (var suitCards in suitCardDict.Values)
            {
                if (suitCards.Count != 2) continue;
                var cardGroupList =  new CardGroupList(suitCards);
                cardGroupList.Add(group.LZCards.First());
                groupList.Add(cardGroupList);
                break;
            }
            return new List<CardGroupList>(0);
        }
    }
}