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

namespace БлэкДжек.Components // Замените BlazorBlackjack на имя вашего проекта
{
    public class Deck
    {
        public List<Card> Cards { get; private set; }

        public Deck()
        {
            InitializeDeck();
        }

        private void InitializeDeck()
        {
            Cards = new List<Card>();
            string[] suits = { "♥", "♦", "♣", "♠" };
            string[] ranks = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A" };

            foreach (var suit in suits)
            {
                foreach (var rank in ranks)
                {
                    int value = 0;
                    if (int.TryParse(rank, out int numValue))
                    {
                        value = numValue;
                    }
                    else if (rank == "J" || rank == "Q" || rank == "K")
                    {
                        value = 10;
                    }
                    else if (rank == "A")
                    {
                        value = 11; // Туз по умолчанию 11
                    }
                    Cards.Add(new Card(suit, rank, value));
                }
            }
        }

        public void Shuffle()
        {
            Random rng = new Random();
            Cards = Cards.OrderBy(c => rng.Next()).ToList();
        }

        public Card DealCard()
        {
            if (Cards.Count == 0)
            {
                // Вместо возврата null, пересоздаем колоду
                InitializeDeck();
                Shuffle();
            }

            Card card = Cards[0];
            Cards.RemoveAt(0);
            return card;
        }



    }
}