// Copyright (c) 2022 Dominic Masters
// 
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT

#pragma once
#include "PokerPlayer.hpp"

/** The default blind cost for the big blind. */
#define POKER_BLIND_BIG_DEFAULT 600
/** The default blind cost for the small blind. (Defaults half big blind) */
#define POKER_BLIND_SMALL_DEFAULT (POKER_BLIND_BIG_DEFAULT/2)

/** How many cards are dealt for the flop, turn and river */
#define POKER_FLOP_CARD_COUNT 3
#define POKER_TURN_CARD_COUNT 1
#define POKER_RIVER_CARD_COUNT 1

namespace Dawn {
  class PokerGame : public SceneItemComponent {
    protected:
      std::vector<struct Card> deck;
      std::vector<struct Card> grave;
      std::vector<struct Card> community;
      uint8_t dealerIndex;
      uint8_t smallBlindIndex;
      uint8_t bigBlindIndex;
      int32_t smallBlind = POKER_BLIND_SMALL_DEFAULT;
      int32_t bigBlind = POKER_BLIND_BIG_DEFAULT;

    public:
      std::vector<PokerPlayer*> players;
      std::vector<struct PokerPot> pots;
      uint8_t betterIndex;

      PokerGame(std::weak_ptr<SceneItem> item);

      void onStart() override;

      void newGame();
      void newRound();
      void newBettingRound();
      void takeBlinds();
      void setBlinds(int32_t small, int32_t big);
      uint8_t getRemainingBettersCount();
      int32_t getCurrentCallValue();
      uint8_t getNextBetterIndex();
      void setDealer(uint8_t dealer);
      void newDealer();
      void burnCard();
      void dealCard(PokerPlayer *player);
      void dealToEveryone(uint8_t count);
      void turn(uint8_t count);
      uint8_t getCountOfCardsToTurn();
      uint8_t getRemainingPlayersCount();

      friend class PokerPlayer;
  };
}