import { z } from 'zod';

export const worldSummarySchema = z.object({
  name: z.string(),
  path: z.string(),
  sizeBytes: z.string(),
  hasLevelDat: z.boolean(),
});

export const worldInfoResponseSchema = z.object({
  activeWorldName: z.string(),
  worlds: z.array(worldSummarySchema),
});

export const initiateWorldUploadSchema = z.object({
  worldName: z
    .string()
    .min(1)
    .max(64)
    .regex(/^[a-zA-Z0-9_-]+$/, 'Invalid world name'),
});

export const worldUploadInitResponseSchema = z.object({
  uploadId: z.string().uuid(),
  uploadUrl: z.string().url(),
  expiresAt: z.string().datetime(),
  s3Key: z.string(),
});

export const worldUploadResponseSchema = z.object({
  id: z.string().uuid(),
  serverId: z.string().uuid(),
  status: z.enum([
    'PENDING',
    'UPLOADING',
    'VALIDATING',
    'READY',
    'COMPLETED',
    'FAILED',
  ]),
  worldName: z.string(),
  sizeBytes: z.string().nullable(),
  failureReason: z.string().nullable(),
  createdAt: z.string().datetime(),
  completedAt: z.string().datetime().nullable(),
});

export const worldDownloadUrlResponseSchema = z.object({
  downloadUrl: z.string().url(),
  expiresAt: z.string().datetime(),
  backupId: z.string().uuid(),
});

export type WorldSummary = z.infer<typeof worldSummarySchema>;
export type WorldInfoResponse = z.infer<typeof worldInfoResponseSchema>;
export type InitiateWorldUpload = z.infer<typeof initiateWorldUploadSchema>;
export type WorldUploadInitResponse = z.infer<typeof worldUploadInitResponseSchema>;
export type WorldUploadResponse = z.infer<typeof worldUploadResponseSchema>;
export type WorldDownloadUrlResponse = z.infer<typeof worldDownloadUrlResponseSchema>;
