import { z } from 'zod';
import { SurvivorStateSchema } from './survivor';

export const MissionStateSchema = z.enum([
  'lobby',
  'active',
  'success',
  'sacrifice',
  'abandoned',
]);
export type MissionState = z.infer<typeof MissionStateSchema>;

export const MissionParticipantSchema = z.object({
  survivorId: z.uuid(),
  state: SurvivorStateSchema,
  hookCount: z.number().int().min(0).max(2),
});
export type MissionParticipant = z.infer<typeof MissionParticipantSchema>;

export const MissionDurationMinutesSchema = z.union([
  z.literal(10),
  z.literal(20),
  z.literal(30),
]);
export type MissionDurationMinutes = z.infer<typeof MissionDurationMinutesSchema>;

export const MissionSchema = z.object({
  id: z.uuid(),
  groupId: z.uuid().nullable(),
  participants: z.array(MissionParticipantSchema).min(1).max(4),
  difficulty: z.number().int().min(1).max(3),
  durationMinutes: MissionDurationMinutesSchema.default(20),
  status: MissionStateSchema,
  killerName: z.string().optional(),
  encounterLibraryVersion: z.string().min(1),
  nextTickAt: z.iso.datetime(),
  tickIndex: z.number().int().min(0),
  startedAt: z.iso.datetime(),
  endedAt: z.iso.datetime().nullable(),
});
export type Mission = z.infer<typeof MissionSchema>;
