(* this structure is used for both getting information about a match, and
   challenging someone.  When getting a match, if confirmation is true,
   then this is just a confirmation of a match we created. *)
type a_match = { stored: bool; is_rated: bool;
		 my_time: int; op_time: int;
		 my_inc: int; op_inc: int;
		 my_def: int; op_def: int;
		 my_color: Board.piece; rnd_color: bool;
		 op_name: string;
		 max_win: int; min_win: int;
		 min_loss: int; max_loss: int;
		 confirmation: bool }

(* this can be returned by get to inform of a match that was created between
   two players. *)
type create = { black: string; white: string;
		b_trust: bool; w_trust: bool; rated: bool }

type who_elem = { name: string;
		  blitz: int; standard: int; (* ratings *)
		  registered: bool; playing: bool; is_open: bool;
		  rated: bool; trust: bool }

(* used to get a board from IOS *)
type board = { who: string;		(* names of players *)
	       num: int;		(* game number *)
	       board: (Board.piece option) array;
	       time_w: int; time_b: int; (* time left in seconds *)
	       def_w: int; def_b: int;	(*default time*)
	       inc_w: int; inc_b: int;	(*increment per move*)
	       turn_color: Board.piece;
	       my_turn: bool;
	       last_move: Board.move;
	       last_move_no: int;
	       last_value: float }

type ios_get =
  | None_get
  | Match_get of a_match
  | Board of board
  | Moves of Board.move list
  | Game_end
  | Game_create of create
  | Look of board
  | Who_get of who_elem list

type ios_put =
  | Who_put
  | Match_put of a_match
  | Move of Board.move * float * float	(* move, time, value *)
  | Accept of string			(* name *)
  | Decline of string * string		(* name, reason *)


(* host, port *)
external connect : string -> int -> unit = "cios_connect"
external disconnect : unit -> unit = "cios_disconnect"
(* name, password, echo, input *)
external logon : string -> string -> bool -> bool -> unit = "cios_logon"
external get : unit -> ios_get = "cios_get"
external put : ios_put -> unit = "cios_put"
external put_str : string -> unit = "cios_put_str"
(* time, inc, def, color, min_rating, max_rating, must_rated, best *)
external challenge : int -> int -> int -> Board.piece option ->
  int -> int -> bool -> bool -> unit
      = "cios_challenge_byte" "cios_challenge"
      
