import { z } from 'zod';

export const gameNodeStatusSchema = z.enum([
  'ONLINE',
  'OFFLINE',
  'MAINTENANCE',
  'DRAINING',
  'UNREACHABLE',
]);

export const nodeSummarySchema = z.object({
  id: z.string().uuid(),
  name: z.string(),
  hostname: z.string(),
  status: gameNodeStatusSchema,
  maxServers: z.number().int(),
  maxRamMb: z.number().int(),
  platformRamMb: z.number().int(),
  activeServers: z.number().int(),
  reservedRamMb: z.number().int(),
  availableRamMb: z.number().int(),
  lastHeartbeatAt: z.string().datetime().nullable(),
  agentVersion: z.string().nullable(),
  drainRequestedAt: z.string().datetime().nullable(),
  createdAt: z.string().datetime(),
});

export const nodeListResponseSchema = z.object({
  nodes: z.array(nodeSummarySchema),
});

export const startQueueStatusSchema = z.enum([
  'QUEUED',
  'DISPATCHED',
  'CANCELLED',
  'EXPIRED',
]);

export const startQueueEntrySchema = z.object({
  serverId: z.string().uuid(),
  nodeId: z.string().uuid(),
  status: startQueueStatusSchema,
  priority: z.number().int(),
  position: z.number().int().nullable(),
  requestedAt: z.string().datetime(),
  expiresAt: z.string().datetime().nullable(),
});

export const startQueueResponseSchema = z.object({
  entry: startQueueEntrySchema.nullable(),
});

export type GameNodeStatus = z.infer<typeof gameNodeStatusSchema>;
export type NodeSummary = z.infer<typeof nodeSummarySchema>;
export type NodeListResponse = z.infer<typeof nodeListResponseSchema>;
export type StartQueueEntry = z.infer<typeof startQueueEntrySchema>;
export type StartQueueResponse = z.infer<typeof startQueueResponseSchema>;
