/**
 * @ai-summary Zod validation schemas for backup API endpoints
 * @ai-context Request validation for backup operations
 */

import { z } from 'zod';

// ============================================
// Backup Operations
// ============================================

export const listBackupsQuerySchema = z.object({
  page: z.coerce.number().int().positive().optional().default(1),
  pageSize: z.coerce.number().int().min(1).max(100).optional().default(20),
  status: z.enum(['in_progress', 'completed', 'failed']).optional(),
  backupType: z.enum(['scheduled', 'manual']).optional(),
  sortBy: z.enum(['startedAt', 'fileSizeBytes', 'status']).optional().default('startedAt'),
  sortOrder: z.enum(['asc', 'desc']).optional().default('desc'),
});

export const createBackupBodySchema = z.object({
  name: z.string().min(1).max(100).optional(),
  includeDocuments: z.boolean().optional().default(true),
});

export const backupIdParamSchema = z.object({
  id: z.string().uuid(),
});

// ============================================
// Restore Operations
// ============================================

export const restoreBodySchema = z.object({
  createSafetyBackup: z.boolean().optional().default(true),
});

// ============================================
// Schedule Operations
// ============================================

export const createScheduleBodySchema = z.object({
  name: z.string().min(1).max(100),
  frequency: z.enum(['hourly', 'daily', 'weekly', 'monthly']),
  retentionCount: z.number().int().min(1).max(365).optional().default(7),
  isEnabled: z.boolean().optional().default(true),
});

export const updateScheduleBodySchema = z.object({
  name: z.string().min(1).max(100).optional(),
  frequency: z.enum(['hourly', 'daily', 'weekly', 'monthly']).optional(),
  retentionCount: z.number().int().min(1).max(365).optional(),
  isEnabled: z.boolean().optional(),
});

export const scheduleIdParamSchema = z.object({
  id: z.string().uuid(),
});

// ============================================
// Settings Operations
// ============================================

export const updateSettingsBodySchema = z.object({
  emailOnSuccess: z.boolean().optional(),
  emailOnFailure: z.boolean().optional(),
  adminEmail: z.string().email().or(z.literal('')).optional(),
  maxBackupSizeMb: z.number().int().min(100).max(10240).optional(),
  compressionEnabled: z.boolean().optional(),
});

// ============================================
// Type Exports
// ============================================

export type ListBackupsQuery = z.infer<typeof listBackupsQuerySchema>;
export type CreateBackupBody = z.infer<typeof createBackupBodySchema>;
export type BackupIdParam = z.infer<typeof backupIdParamSchema>;
export type RestoreBody = z.infer<typeof restoreBodySchema>;
export type CreateScheduleBody = z.infer<typeof createScheduleBodySchema>;
export type UpdateScheduleBody = z.infer<typeof updateScheduleBodySchema>;
export type ScheduleIdParam = z.infer<typeof scheduleIdParamSchema>;
export type UpdateSettingsBody = z.infer<typeof updateSettingsBodySchema>;
