#ifndef _HF_GAME_
#define _HF_GAME_

#include <stdbool.h>

typedef struct Game Game;

#include "card.h"
#include "field_multiplier.h"
#include "teyaku.h"
#include "dekiyaku.h"
#include "points.h"

typedef enum GameState {
  GAME_STATE_INITIALIZING,
  GAME_STATE_DEALING,
  GAME_STATE_CALCULATING_FIELD_MULTIPLIER,
  GAME_STATE_CALCULATING_TEYAKU,
  GAME_STATE_PLAYER_CHOOSING_FROM_HAND,
  GAME_STATE_PLAYER_CHOOSING_TARGET,
  GAME_STATE_PLAYER_FROM_DECK,
  GAME_STATE_PLAYER_HAS_DEKIYAKU,
  GAME_STATE_RIGHT_PLAYING,
  GAME_STATE_RIGHT_FROM_DECK,
  GAME_STATE_LEFT_PLAYING,
  GAME_STATE_LEFT_FROM_DECK,
  GAME_STATE_CALCULATING_SCORES,
  GAME_STATE_CALCULATING_DEKIYAKU_SCORE,
} GameState;

struct Game {
  GameState state;
  bool should_close;
  Card cards[48];
  Texture2D cards_texture;
  Hand player_hand, left_hand, right_hand;
  Hand deck, field;
  Hand player_scored, left_scored, right_scored;
  FieldMultiplier *field_multiplier;
  Teyaku player_teyaku, left_teyaku, right_teyaku;
  Dekiyaku player_dekiyaku, left_dekiyaku, right_dekiyaku;
  DekiyakuAction player_dekiyaku_action;
  int player_dekiyaku_score, left_dekiyaku_score, right_dekiyaku_score;
  Card *current_play_from_hand, *current_play_target;
  int player_points, right_points, left_points, temp_points;
  char player_points_string[20], left_points_string[20], right_points_string[20];
  int kan_value;
};

void initialize_game(Game *g);
void run_until_closing(Game *g);
void transfer_points(Game *g, int *to, int *from, int amount);
void transfer_kan(Game *g, int *to, int *from, int amount);

#endif