import { z } from 'zod';

// ── Maintenance Modes ────────────────────────────────────────

export type MaintenanceMode = 'off' | 'read_only' | 'maintenance' | 'emergency';

export interface MaintenanceConfig {
  mode: MaintenanceMode;
  message: string;
  adminMessage?: string;
  bypassRoles: string[];
  bypassIPs: string[];
  scheduledStart?: string;
  scheduledEnd?: string;
  affectedServices: string[];
  updatedAt: string;
  updatedBy: string;
}

// ── Schemas ──────────────────────────────────────────────────

export const UpdateMaintenanceSchema = z.object({
  mode: z.enum(['off', 'read_only', 'maintenance', 'emergency']),
  message: z.string().min(1).max(500),
  adminMessage: z.string().max(500).optional(),
  bypassRoles: z.array(z.string()).default([]),
  bypassIPs: z.array(z.string()).default([]),
  scheduledStart: z.string().datetime().optional(),
  scheduledEnd: z.string().datetime().optional(),
  affectedServices: z.array(z.string()).default(['*']),
});

export type UpdateMaintenanceInput = z.infer<typeof UpdateMaintenanceSchema>;

// ── Maintenance Window (scheduled) ───────────────────────────

export interface MaintenanceWindow {
  id: string;
  productId: string;
  title: string;
  message: string;
  mode: MaintenanceMode;
  scheduledStart: string;
  scheduledEnd: string;
  affectedServices: string[];
  createdBy: string;
  createdAt: string;
  _ts?: number;
}

export const CreateMaintenanceWindowSchema = z.object({
  title: z.string().min(1).max(200),
  message: z.string().min(1).max(500),
  mode: z.enum(['read_only', 'maintenance']).default('maintenance'),
  scheduledStart: z.string().datetime(),
  scheduledEnd: z.string().datetime(),
  affectedServices: z.array(z.string()).default(['*']),
});
