import { z } from 'zod'; export const Coordinate = z.object({ rank: z.number(), file: z.number(), }); export type Coordinate = z.infer; export const Side = z.enum(['white', 'black']); export type Side = z.infer; export const PieceType = z.enum(['king', 'queen', 'rook', 'bishop', 'knight', 'pawn']); export type PieceType = z.infer; export const Piece = z.object({ side: Side, ty: PieceType, }); export type Piece = z.infer; export interface Move { from: Coordinate; to: Coordinate; set_en_passant: Coordinate | null; other: Move | null; promotions: Piece[] | null; } export const Move: z.ZodType = z.lazy(() => z.object({ from: Coordinate, to: Coordinate, set_en_passant: z.nullable(Coordinate), other: z.nullable(Move), promotions: z.nullable(z.array(Piece)), })); export const Board = z.array(z.nullable(Piece)); export type Board = z.infer; export const BoardUpdateEvent = z.object({ board: Board, }); export type BoardUpdateEvent = z.infer; export const PossibleMovesEvent = z.object({ moves: z.array(Move), }); export type PossibleMovesEvent = z.infer; export const StartGameEvent = z.object({ side: Side, }); export type StartGameEvent = z.infer; export const ServerChessEvent = z.discriminatedUnion("event", [ z.object({ event: z.literal('BoardUpdate'), data: BoardUpdateEvent }), z.object({ event: z.literal('PossibleMoves'), data: PossibleMovesEvent }), z.object({ event: z.literal('StartGame'), data: StartGameEvent }) ]); export type ServerChessEvent = z.infer;