// Insurance Portal — mock data

const INS_AGENT = {
  name: 'Vinay Krishnan',
  email: 'v.krishnan@ariskcorp.com',
  company: 'A-Risk Underwriting Group',
  agentId: 'AGT-0481',
  scansToday: 12,
};

// Recent scans — what an agent sees on home
const INS_RECENT_SCANS = [
  { id: 'SCN-4128', patient: 'Anita Desai',     insuranceId: 'PLN-92831', date: '2026-05-18 09:42', matchRate: 96.4, mismatches: 2,  csvMissing: 1, fraudLevel: 'verified_clean', total: 84, sessions: 3, durationMs: 11400 },
  { id: 'SCN-4127', patient: 'Suresh Patel',    insuranceId: 'PLN-44182', date: '2026-05-18 09:18', matchRate: 91.0, mismatches: 7,  csvMissing: 2, fraudLevel: 'low_risk',        total: 78, sessions: 2, durationMs: 9800 },
  { id: 'SCN-4126', patient: 'Rahul Sharma',    insuranceId: 'PLN-77194', date: '2026-05-18 08:54', matchRate: 78.2, mismatches: 19, csvMissing: 0, fraudLevel: 'medium_risk',     total: 87, sessions: 4, durationMs: 14200 },
  { id: 'SCN-4125', patient: 'Sunita Kumar',    insuranceId: 'PLN-30922', date: '2026-05-17 18:32', matchRate: 42.8, mismatches: 54, csvMissing: 8, fraudLevel: 'critical_risk',   total: 95, sessions: 5, durationMs: 18600 },
  { id: 'SCN-4124', patient: 'Vikram Shah',     insuranceId: 'PLN-58291', date: '2026-05-17 16:11', matchRate: 88.4, mismatches: 9,  csvMissing: 3, fraudLevel: 'low_risk',        total: 78, sessions: 3, durationMs: 10100 },
  { id: 'SCN-4123', patient: 'Meena Joshi',     insuranceId: 'PLN-12889', date: '2026-05-17 14:48', matchRate: 65.1, mismatches: 27, csvMissing: 2, fraudLevel: 'high_risk',       total: 80, sessions: 4, durationMs: 12800 },
  { id: 'SCN-4122', patient: 'Karthik Iyer',    insuranceId: 'PLN-90011', date: '2026-05-17 11:32', matchRate: 99.1, mismatches: 1,  csvMissing: 0, fraudLevel: 'verified_clean', total: 110, sessions: 2, durationMs: 8400 },
  { id: 'SCN-4121', patient: 'Anjali Mehra',    insuranceId: 'PLN-29844', date: '2026-05-17 10:20', matchRate: 93.2, mismatches: 5,  csvMissing: 1, fraudLevel: 'verified_clean', total: 73, sessions: 2, durationMs: 8800 },
];

// Risk leaderboard — highest-risk patients flagged
const INS_RISK_LEADERBOARD = [
  { patient: 'Sunita Kumar',  insuranceId: 'PLN-30922', score: 92, level: 'critical_risk', scans: 3, flags: 'Multiple HR mismatches · CSV gaps · device swap' },
  { patient: 'Meena Joshi',   insuranceId: 'PLN-12889', score: 78, level: 'high_risk',    scans: 5, flags: 'BP readings inconsistent with CSV' },
  { patient: 'Rahul Sharma',  insuranceId: 'PLN-77194', score: 64, level: 'medium_risk',  scans: 4, flags: 'Temperature drift > 0.8°C between systems' },
  { patient: 'Deepa Varma',   insuranceId: 'PLN-66120', score: 58, level: 'medium_risk',  scans: 2, flags: 'SpO₂ readings stale; pattern repetition' },
  { patient: 'Ravi Pillai',   insuranceId: 'PLN-44099', score: 52, level: 'medium_risk',  scans: 3, flags: 'Sensor disconnect events overlap claims' },
];

// Aggregate KPIs over rolling 7 days
const INS_KPIS = {
  totalScans: 287,
  matchRate: 89.4,
  flagged: 18,
  fraudSaved: 4280000, // ₹
  // Sparkline (last 14 days)
  scansSpark: [22, 28, 31, 26, 35, 41, 38, 44, 39, 48, 52, 47, 56, 61],
  matchRateSpark: [88.1, 87.2, 89.5, 90.1, 88.7, 91.4, 89.9, 92.0, 91.2, 90.7, 89.5, 90.4, 89.1, 89.4],
  flaggedSpark: [3, 2, 4, 3, 2, 1, 4, 5, 3, 2, 4, 6, 5, 4],
  fraudSavedSpark: [180, 240, 310, 280, 320, 410, 380, 420, 390, 480, 510, 470, 560, 610],
};

// Trend chart — match-rate over 30 days
const INS_TRENDS = Array.from({ length: 30 }, (_, i) => {
  const base = 88 + Math.sin(i / 3) * 3 + (Math.random() - 0.5) * 2;
  return {
    day: i + 1,
    matchRate: parseFloat(base.toFixed(1)),
    scans: Math.round(30 + Math.sin(i / 2) * 12 + Math.random() * 8),
    flagged: Math.round(2 + Math.random() * 4),
  };
});

// Field analysis — most-mismatched vital
const INS_FIELD_ANALYSIS = [
  { field: 'Heart Rate',        mismatches: 142, color: '#06b6d4' },
  { field: 'Blood Pressure',    mismatches: 98,  color: '#0891b2' },
  { field: 'SpO₂',              mismatches: 76,  color: '#67e8f9' },
  { field: 'Temperature',       mismatches: 54,  color: '#14b8a6' },
  { field: 'Respiration',       mismatches: 31,  color: '#5eead4' },
];

// Detail records for a scan (used in scan results screen)
const INS_SCAN_DETAIL = {
  patient: 'Rahul Sharma',
  insuranceId: 'PLN-77194',
  scanId: 'SCN-4126',
  totalScans: 87,
  matches: 68,
  mismatches: 19,
  csvMissing: 0,
  matchRate: 78.2,
  fraudScore: 31,
  fraudLevel: 'medium_risk',
  csvCoverage: 100,
  sessions: [
    { idx: 1, device: 'AA:BB:CC:DD:01:01', start: '2026-05-15 09:30', end: '2026-05-15 18:42', duration: '9h 12m', vitals: 22, status: 'completed' },
    { idx: 2, device: 'AA:BB:CC:DD:01:01', start: '2026-05-16 08:11', end: '2026-05-16 19:38', duration: '11h 27m', vitals: 28, status: 'completed' },
    { idx: 3, device: 'AA:BB:CC:DD:01:01', start: '2026-05-17 07:45', end: '2026-05-17 21:12', duration: '13h 27m', vitals: 31, status: 'completed' },
    { idx: 4, device: 'AA:BB:CC:DD:01:01', start: '2026-05-18 08:01', end: 'Active', duration: '—', vitals: 6, status: 'active' },
  ],
  records: [
    { time: '2026-05-17 14:32', vital: 'Heart Rate',     db: '132', csv: '78',  delta: '+69%', status: 'mismatch', session: 3 },
    { time: '2026-05-17 14:30', vital: 'SpO₂',           db: '94.2', csv: '94.1', delta: '+0.1', status: 'match', session: 3 },
    { time: '2026-05-17 14:28', vital: 'BP Systolic',    db: '156', csv: '124', delta: '+25%', status: 'mismatch', session: 3 },
    { time: '2026-05-17 14:25', vital: 'Temperature',    db: '38.4', csv: '37.0', delta: '+3.8%', status: 'mismatch', session: 3 },
    { time: '2026-05-17 14:21', vital: 'Heart Rate',     db: '128', csv: '78',  delta: '+64%', status: 'mismatch', session: 3 },
    { time: '2026-05-17 14:18', vital: 'Respiration',    db: '24',  csv: '16',  delta: '+50%', status: 'mismatch', session: 3 },
    { time: '2026-05-17 14:15', vital: 'BP Diastolic',   db: '98',  csv: '82',  delta: '+19%', status: 'mismatch', session: 3 },
    { time: '2026-05-17 14:12', vital: 'SpO₂',           db: '95.0', csv: '95.0', delta: '0%',  status: 'match', session: 3 },
    { time: '2026-05-17 14:08', vital: 'Heart Rate',     db: '102', csv: '76',  delta: '+34%', status: 'mismatch', session: 3 },
    { time: '2026-05-17 14:05', vital: 'Temperature',    db: '37.1', csv: '37.0', delta: '+0.3%', status: 'match', session: 3 },
  ],
};

const INS_FRAUD_LEVELS = {
  verified_clean: { label: 'Verified Clean', color: '#16a34a', bg: 'rgba(22,163,74,0.14)' },
  low_risk:       { label: 'Low Risk',       color: '#65a30d', bg: 'rgba(101,163,13,0.14)' },
  medium_risk:    { label: 'Medium Risk',    color: '#ca8a04', bg: 'rgba(202,138,4,0.14)' },
  high_risk:      { label: 'High Risk',      color: '#ea580c', bg: 'rgba(234,88,12,0.14)' },
  critical_risk:  { label: 'Critical Risk',  color: '#dc2626', bg: 'rgba(220,38,38,0.14)' },
};

Object.assign(window, {
  INS_AGENT, INS_RECENT_SCANS, INS_RISK_LEADERBOARD, INS_KPIS,
  INS_TRENDS, INS_FIELD_ANALYSIS, INS_SCAN_DETAIL, INS_FRAUD_LEVELS,
});
