import { z } from 'zod';
import { GAME_FINISHED_REASON, GAME_STATUS, GAME_TYPE, GAME_WARNING_EVENT } from './Game.const';

export const gameTypeSchema = z.enum(GAME_TYPE);

export const gameStatusSchema = z.enum(GAME_STATUS);

export const gameFinishedReasonSchema = z.enum(GAME_FINISHED_REASON);

export const gameWarningEventSchema = z.enum(GAME_WARNING_EVENT);

export const gameKartStateSchema = z.object({
  coins: z.number(),
});

export const kartRankingItemSchema = z.object({
  kartGuid: z.string(),
  position: z.number(),
  time: z.number(),
});

export const gameSchema = z.object({
  id: z.number(),
  status: gameStatusSchema,
  kartsGuids: z.array(z.string()),
  powerUpsIds: z.array(z.string()),
  gameTrackId: z.string(),
  type: gameTypeSchema,
  coins: z.number(),
  time: z.number(),
  speedConfig: z.number(),
  createdAt: z.date(),
  startedAt: z.date().optional(),
  finishedAt: z.date().optional(),
  finishedReason: gameFinishedReasonSchema.optional(),
  kartsState: z.record(z.string(), gameKartStateSchema),
  gameRanking: z.array(kartRankingItemSchema),
});
