/**
 * UpTime Sentinel — Executive Command data contract.
 *
 * Mirrors the `SENTINEL_DATA` shape from the design handoff
 * (docs/design_handoff_uptime_sentinel/lib/mock-data.js) — which in turn
 * matches the `/api/reports/executive` response. Keep these in lockstep:
 * the mock provider and the real polling API both return `SentinelData`.
 */

export type MonitorType = 'https' | 'tcp' | 'ping';
export type MonitorStatus = 'up' | 'down' | 'unknown';
export type InsightType = 'success' | 'warning' | 'critical' | 'info';

/** Health/severity bucket used for all status coloring. */
export type StatusLevel = 'healthy' | 'warning' | 'critical';

export interface Overview {
    totalMonitors: number;
    activeMonitors: number;
    overallUptime: number; // %
    uptimeTrend: number; // Δ% vs last month
    activeIncidents: number;
    incidentsTrend: number; // % change
    avgResponseTime: number; // ms
    responseTrend: number; // % change
}

export interface MonthlyTrend {
    month: string; // e.g. "Jun 25"
    uptime: number; // %
    incidents: number;
    responseTime: number; // ms
}

export interface TopIssue {
    id: string;
    name: string;
    type: MonitorType;
    downtime: number; // minutes
    incidents: number;
    lastIncident: string; // ISO
}

export interface CountryBreakdown {
    country: string;
    code: string; // KE, US, IN, NG, UK, ZA, Global
    monitors: number;
    uptime: number; // %
    incidents: number;
}

export interface Insight {
    type: InsightType;
    title: string;
    description: string;
    metric?: string;
}

export interface ResponsePercentiles {
    p50: number;
    p95: number;
    p99: number;
}

export interface RecentAlert {
    monitorName: string;
    status: 'down' | 'up';
    timestamp: string; // ISO
    responseTime: number; // ms (0 when down)
}

export interface MonitorRow {
    id: string;
    name: string;
    type: MonitorType;
    status: MonitorStatus;
    responseTime: number; // ms (0 when down/unknown)
    url: string;
    region: string; // country code, matches CountryBreakdown.code
    // Geolocation resolved from the monitor's host/IP (the existing
    // GeoLocationService pipeline writes these on create/update). Null
    // when unresolved (private IP / internal host) — the Network map
    // falls back to the region centroid in that case.
    lat?: number | null;
    lon?: number | null;
    city?: string | null;
}

export interface SentinelData {
    overview: Overview;
    monthlyTrends: MonthlyTrend[];
    topIssues: TopIssue[];
    countryBreakdown: CountryBreakdown[];
    insights: Insight[];
    responsePercentiles: ResponsePercentiles;
    recentAlerts: RecentAlert[];
    monitors: MonitorRow[];
    lastUpdated: string; // ISO
}
