import { z } from 'zod';
import { checkpointSchema } from '../checkpoint';
import { colorNameSchema } from '../color';
import { gameTypeSchema } from '../game';
import {
  configDiskSensorBallShooterModuleOptionsSchema,
  configureBallSensorDiskThrowerModuleOptionsSchema,
} from '../hardware';

export const gameTrackGameDefaultValuesSchema = z.object({
  speed: z.array(z.number()),
  powerUpIds: z.array(z.string()),
});

export const gameTrackKartsConfigSchema = z.object({
  defaultSpeed: z.number().min(0).max(100),
  powerUpTime: z.number().min(1).max(25),
  rgbBrightness: z.number().min(0).max(100),
  flagBrightness: z.number().min(0).max(100),
  diskSensorBallShooter: configDiskSensorBallShooterModuleOptionsSchema,
  ballSensorDiskThrower: configureBallSensorDiskThrowerModuleOptionsSchema,
  lowSpeed: z.number().min(0).max(100),
});

export const gameTrackKartConfigSchema = z.object({
  gameTrackId: z.string(),
  kartId: z.number(),
  color: colorNameSchema,
  kartNumber: z.number(),
  mac: z.string(),
});

export const gameTrackSchema = z.object({
  id: z.string(),
  name: z.string(),
  type: gameTypeSchema,
  checkpoints: z.array(checkpointSchema),
  kartsConfig: gameTrackKartsConfigSchema,
  macAddress: z.string().optional(),
  isConnected: z.boolean(),
  gameDefaultValues: gameTrackGameDefaultValuesSchema.optional(),
});
