﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsoleApplication1.Entities.Cards;

namespace ConsoleApplication1.Entities
{
    public class Deck : IDeck
    {
        private List<ICard> CurrentDeck = new List<ICard>();

        public Deck()
        {
            List<ICard> deck = CurrentDeck;
            string[] colors = Enum.GetNames(typeof(Color));
            string[] values = Enum.GetNames(typeof(ValueCard));
            foreach (var color in colors)
            {
                foreach (var value in values)
                {
                    var card = new Card()
                                {
                                    ColorCard = (Color)Enum.Parse(typeof(Color), color),
                                    ValueCard = (ValueCard)Enum.Parse(typeof(ValueCard), value)
                                };
                    if (card.ColorCard == Color.BLUE || card.ColorCard == Color.GREEN || 
                        card.ColorCard == Color.RED  || card.ColorCard == Color.YELLOW)
                    {
                        if (card.ValueCard != ValueCard.ORDERFLOWERS &&
                            card.ValueCard != ValueCard.TAKEFOUR)
                        {
                            if (card.ValueCard == ValueCard.ZERO)
                            {
                                deck.Add(card);
                            }
                            else
                            {
                                deck.Add(card);
                                deck.Add(card);
                            }
                        }                        
                    }
                    if (card.ColorCard == Color.WILD)
                    {
                        if (card.ValueCard != ValueCard.ORDERFLOWERS &&
                            card.ValueCard != ValueCard.TAKEFOUR)
                            continue;
                        deck.Add(card);
                        deck.Add(card);
                        deck.Add(card);
                        deck.Add(card);
                    }
                }
            }

            this.CurrentDeck = deck;
        }

        public List<ICard> GetDeck()
        {
            return this.CurrentDeck;
        }

        public IDeck Sort()
        {
            throw new NotImplementedException();
        }
    }
}
