using System;
using System.Collections.Generic;
using TheGameExtreme.model.card;
using TheGameExtreme.model.card.cardType;
using TheGameExtreme.model.gameActions.abstractRules;
using TheGameExtreme.model.piles;
using TheGameExtreme.Resx;

namespace TheGameExtreme.model.gameActions.fraction
{
    public class TerminerSonTourFraction : TerminerSonTour
    {
        public TerminerSonTourFraction(Piles ListOrderedStacks) : base(ListOrderedStacks)
        {
        }

        public override bool end(List<Card> CurrentHand, List<Card> CurrentCardPlayed)
        {
            if (CurrentHand.Count == 0 || CurrentCardPlayed.Count >= 2)
            {
                // Vérifier la fin du jeu
                return true;
            }
            else
            {
                ErrorMessage = AppResources.StrCardPlayedLessThanTwo;
                return false;
            }
        }

        protected override bool testEndGame(List<Card> playableCard)
        {
            if (playableCard.Count < 2)
            {
                return false;
            }
            return true;
        }

        protected override void tryToFindSoluce(List<Card> playableCard, List<Card> CurrentHand)
        {
            CurrentHand.ForEach(card =>
            {
                for (int i = 0; i < ListOrderedStacks.Size; i++)
                {
                    if (i < (ListOrderedStacks.Size * 0.5))
                    {
                        if (card.Value > ListOrderedStacks.getStack(i).Peek().Value)
                        {
                            playableCard.Add(card);
                        }
                    }
                    else if (card.Value < ListOrderedStacks.getStack(i).Peek().Value)
                    {
                        playableCard.Add(card);
                    }
                    else if (((FractionCard)card).Fraction.isMultiple(((FractionCard)ListOrderedStacks.getStack(i).Peek()).Fraction))
                    {
                        playableCard.Add(card);
                    }
                }
            });
        }
    }
}
