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

#pragma once
#include "../libs.h"
#include "card.h"
#include "player.h"

/** How many cards the dealer can hold in their hand */
#define POKER_DEALER_HAND_SIZE 5

/** How many cards the grave can hold */
#define POKER_DEALER_GRAVE_SIZE CARD_DECK_SIZE

/** Which VN Character index is the dealer */
#define POKER_DEALER_INDEX POKER_PLAYER_HUMAN_INDEX

/** Representation of the dealer state */
typedef struct {
  /** Current Card Deck */
  card_t deck[CARD_DECK_SIZE];
  uint8_t deckSize;

  /** Dealer Hand */
  card_t cards[POKER_DEALER_HAND_SIZE];
  uint8_t cardsFacing;

  /** Card grave (where spent cards go when burned */
  card_t grave[POKER_DEALER_GRAVE_SIZE];
  uint8_t graveSize;
} pokerdealer_t;

/**
 * Initializes/Resets a dealer state.
 * 
 * @param dealer Dealer's state to reset.
 */
void pokerDealerInit(pokerdealer_t *dealer);

/**
 * Turns over cards from the deck onto the table (from the deck into the dealer
 * hand)
 * 
 * @param dealer Poker dealer instance.
 * @param count Count of cards to deal.
 */
void pokerDealerTurn(pokerdealer_t *dealer, uint8_t count);

/**
 * Burns a set of cards off the top of the deck into the graveyard.
 * 
 * @param dealer Poker dealer instance.
 * @param count Count of cards to burn.
 */
void pokerDealerBurn(pokerdealer_t *dealer, uint8_t count);

/**
 * Deal a card to a player.
 * 
 * @param dealer Poker dealer instance.
 * @param player Poker player to deal to.
 */
void pokerDealerDeal(pokerdealer_t *dealer, pokerplayer_t *player);

/**
 * Deal card(s) to every active player.
 * 
 * @param dealer Poker dealer instance.
 * @param players Array of poker players.
 * @param count Count of cards to deal.
 */
void pokerDealerDealAll(
  pokerdealer_t *dealer, pokerplayer_t *players, uint8_t count
);