import type { DashboardData } from './types';

const now = Date.now();
const ago = (minutes: number) => new Date(now - minutes * 60_000).toISOString();

export const mockDashboardData: DashboardData = {
  generatedAt: new Date(now).toISOString(),
  release: { name: 'zipdiv', version: '0.4.2', status: 'active' },
  summary: {
    clients: 1280,
    activeClients: 1247,
    specFunctions: 9,
    implementations: 32,
    possibleCompositions: 1_492_992,
    activeCompositions: 714,
    telemetryEvents: 48_291,
    populationFailureRate: 1.7,
    previousFailureRate: 6.8,
  },
  implementationsPerFunction: [
    { name: 'Locate EOCD', count: 4 },
    { name: 'Central directory', count: 4 },
    { name: 'Local header', count: 3 },
    { name: 'Decode filename', count: 4 },
    { name: 'Normalize path', count: 4 },
    { name: 'Decompress', count: 4 },
    { name: 'Validate CRC', count: 3 },
    { name: 'Extract entry', count: 3 },
    { name: 'List archive', count: 3 },
  ],
  compositions: [
    { id: 'c-41f2', label: '41F2', clients: 78, share: 6.3, failureRate: 0.9, implementations: ['EOCD·A2', 'PATH·D4', 'CRC·G1'] },
    { id: 'c-a83e', label: 'A83E', clients: 65, share: 5.2, failureRate: 1.1, implementations: ['EOCD·A1', 'PATH·D1', 'CRC·G3'] },
    { id: 'c-90bd', label: '90BD', clients: 53, share: 4.3, failureRate: 1.4, implementations: ['EOCD·A4', 'PATH·D2', 'CRC·G1'] },
    { id: 'c-217c', label: '217C', clients: 46, share: 3.7, failureRate: 1.6, implementations: ['EOCD·A2', 'PATH·D3', 'CRC·G3'] },
    { id: 'c-other', label: '710 other compositions', clients: 1005, share: 80.5, failureRate: 1.8, implementations: [] },
  ],
  implementations: [
    { id: 'path-d4', releaseId: 1, specFunction: 'normalize_extraction_path', variant: 'D4', clients: 0, executions: 41_285, failures: 2048, failureRate: 4.96, relativeRisk: 4.7, confidence: 99.8, status: 'quarantined' },
    { id: 'decompress-f3', releaseId: 1, specFunction: 'decompress_entry', variant: 'F3', clients: 296, executions: 126_941, failures: 3641, failureRate: 2.87, relativeRisk: 3.2, confidence: 99.2, status: 'watch' },
    { id: 'eocd-a3', releaseId: 1, specFunction: 'locate_end_of_central_directory', variant: 'A3', clients: 308, executions: 98_314, failures: 1572, failureRate: 1.60, relativeRisk: 1.8, confidence: 97.4, status: 'watch' },
    { id: 'crc-g2', releaseId: 1, specFunction: 'validate_crc', variant: 'G2', clients: 0, executions: 63_750, failures: 1872, failureRate: 2.94, relativeRisk: 2.9, confidence: 99.5, status: 'quarantined' },
    { id: 'central-b1', releaseId: 1, specFunction: 'parse_central_directory_entry', variant: 'B1', clients: 322, executions: 134_122, failures: 686, failureRate: 0.51, relativeRisk: 0.7, confidence: 86.4, status: 'healthy' },
    { id: 'path-d2', releaseId: 1, specFunction: 'normalize_extraction_path', variant: 'D2', clients: 412, executions: 118_932, failures: 523, failureRate: 0.44, relativeRisk: 0.6, confidence: 91.2, status: 'healthy' },
    { id: 'decompress-f1', releaseId: 1, specFunction: 'decompress_entry', variant: 'F1', clients: 333, executions: 127_731, failures: 715, failureRate: 0.56, relativeRisk: 0.7, confidence: 88.1, status: 'healthy' },
  ],
  interactions: [
    { first: 'EOCD·A3', second: 'DEFLATE·F3', clients: 74, observedFailureRate: 12.8, expectedFailureRate: 3.9, lift: 3.28, confidence: 99.1 },
    { first: 'HEADER·C2', second: 'CRC·G1', clients: 81, observedFailureRate: 4.2, expectedFailureRate: 1.6, lift: 2.63, confidence: 94.7 },
    { first: 'PATH·D3', second: 'EXTRACT·H2', clients: 69, observedFailureRate: 2.7, expectedFailureRate: 1.5, lift: 1.80, confidence: 88.3 },
  ],
  quarantines: [
    { implementationId: 'path-d4', variant: 'PATH·D4', specFunction: 'normalize_extraction_path', quarantinedAt: ago(92), reason: '4.7× relative failure risk', affectedClients: 318, recomposedClients: 318, beforeFailureRate: 6.8, afterFailureRate: 1.7, afterExecutions: 41_285 },
    { implementationId: 'crc-g2', variant: 'CRC·G2', specFunction: 'validate_crc', quarantinedAt: ago(1460), reason: 'Integrity failures above policy threshold', affectedClients: 341, recomposedClients: 341, beforeFailureRate: 5.1, afterFailureRate: 2.3, afterExecutions: 63_750 },
  ],
  healthSequence: [
    { label: 'Baseline', healthyRate: 93.2, executions: 18_200 },
    { label: 'After CG2', implementationId: 'crc-g2', healthyRate: 94.9, executions: 14_300 },
    { label: 'After PD4', implementationId: 'path-d4', healthyRate: 98.3, executions: 15_791 },
  ],
  telemetry: [
    { id: 'evt-1', timestamp: ago(2), kind: 'spec_function_error', severity: 'warning', clientId: 'client…7f2a', implementationId: 'decompress-f3', specFunction: 'decompress_entry', message: 'Unexpected end of DEFLATE stream', recentCalls: ['parse_local_file_header', 'decompress_entry'] },
    { id: 'evt-2', timestamp: ago(6), kind: 'crc_integrity_failure', severity: 'critical', clientId: 'client…19bc', implementationId: 'crc-g1', specFunction: 'validate_crc', message: 'Computed CRC differs from central directory', recentCalls: ['decompress_entry', 'validate_crc'] },
    { id: 'evt-3', timestamp: ago(11), kind: 'recomposition', severity: 'success', clientId: 'client…5ae1', implementationId: 'path-d2', specFunction: 'normalize_extraction_path', message: 'Quarantined PATH·D4 replaced with PATH·D2', recentCalls: [] },
    { id: 'evt-4', timestamp: ago(18), kind: 'timeout', severity: 'warning', clientId: 'client…b331', implementationId: 'eocd-a3', specFunction: 'locate_end_of_central_directory', message: 'Execution exceeded the 1,500 ms contract', recentCalls: ['list_archive', 'locate_end_of_central_directory'] },
    { id: 'evt-5', timestamp: ago(25), kind: 'registration', severity: 'info', clientId: 'client…93d8', implementationId: '—', specFunction: '—', message: 'New client assigned composition 41F2', recentCalls: [] },
  ],
  trend: [
    { label: '10:00', failureRate: 6.9, events: 742 }, { label: '10:30', failureRate: 6.5, events: 711 },
    { label: '11:00', failureRate: 7.2, events: 768 }, { label: '11:30', failureRate: 6.6, events: 725 },
    { label: '12:00', failureRate: 6.8, events: 719 }, { label: '12:30', failureRate: 4.1, events: 491 },
    { label: '13:00', failureRate: 2.9, events: 351 }, { label: '13:30', failureRate: 2.2, events: 292 },
    { label: '14:00', failureRate: 1.7, events: 236 },
  ],
};
