/**
 * 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 "fuck.h"
#include "player.h"

/**
 * Fills the remaining cards for a given poker player winning hand. Essentially
 * this will just take the highest cards and slot them into the array. This also
 * sorts the cards.
 * 
 * @param winning Pointer to the poker winning to fill out.
 */
void pokerWinnerFillRemaining(pokerplayerwinning_t *winning);

/**
 * Calculates and returns the winning state for a given player
 * 
 * @param poker Poker game instance.
 * @param player Player to get the state for.
 * @param winning Output winning state struct to push data in to.
 */
void pokerWinnerGetForPlayer(
  poker_t *poker, pokerplayer_t *player, pokerplayerwinning_t *winning
);

/**
 * Compares two winning sets. The returned card is the kicker if the LEFT side
 * is the winner. If LEFT is not a winner then 0xFF will be returned.
 * 
 * @param left Left winning set.
 * @param right Right winning set.
 * @return The kicker card from left's hand or 0xFF if left is not the winner.
 */
card_t pokerWinnerCompare(
  pokerplayerwinning_t *left, pokerplayerwinning_t *right
);

/**
 * Determines the winning player for the given pot. The pot has participating
 * players, and from those participating players some will be winners. The
 * participants are only the players within the pot who haven't folded or out.
 * 
 * @param poker Poker game instance.
 * @param pot Pot to get the winners for.
 * @param winners Array to store the winner state in.
 * @param winnerPlayers Array to store player indexes of each of the winners.
 * @param winnerCount Pointer to store the count of winners in.
 * @param participants Array to store player indexes of players who participate.
 * @param participantCount Pointer to store the count of participants in.
 */
void pokerWinnerDetermineForPot(
  poker_t *poker,
  pokerpot_t *pot,
  pokerplayerwinning_t winners[POKER_PLAYER_COUNT_MAX],
  uint8_t winnerPlayers[POKER_PLAYER_COUNT_MAX],
  uint8_t *winnerCount,
  uint8_t participants[POKER_PLAYER_COUNT_MAX],
  uint8_t *participantCount
);

/**
 * Get the confidence of the bet for a given winning type.
 * 
 * @param type Winning type type.
 * @return The confidence.
 */
float pokerWinnerGetTypeConfidence(uint8_t type);