import { z } from 'zod';

// ── Service Status ───────────────────────────────────────────

export type ServiceHealth =
  | 'operational'
  | 'degraded'
  | 'partial_outage'
  | 'major_outage'
  | 'maintenance';

export interface ServiceStatus {
  name: string;
  url: string;
  health: ServiceHealth;
  responseTimeMs: number | null;
  lastCheckedAt: string;
  error?: string;
}

export interface PlatformStatus {
  overall: ServiceHealth;
  services: ServiceStatus[];
  checkedAt: string;
  uptimePercent?: number;
}

// ── Incident Schemas ─────────────────────────────────────────

export type IncidentStatus = 'investigating' | 'identified' | 'monitoring' | 'resolved';
export type IncidentSeverity = 'minor' | 'major' | 'critical';

export const CreateIncidentSchema = z.object({
  title: z.string().min(1).max(200),
  severity: z.enum(['minor', 'major', 'critical']),
  message: z.string().min(1).max(2000),
  affectedServices: z.array(z.string()).min(1),
});

export const UpdateIncidentSchema = z.object({
  status: z.enum(['investigating', 'identified', 'monitoring', 'resolved']).optional(),
  message: z.string().min(1).max(2000).optional(),
  severity: z.enum(['minor', 'major', 'critical']).optional(),
});

export interface IncidentUpdate {
  status: IncidentStatus;
  message: string;
  createdAt: string;
}

export interface IncidentDoc {
  id: string;
  productId: string;
  title: string;
  severity: IncidentSeverity;
  status: IncidentStatus;
  affectedServices: string[];
  updates: IncidentUpdate[];
  createdAt: string;
  updatedAt: string;
  resolvedAt?: string;
  _ts?: number;
  _etag?: string;
}
