// Device Management — mock data
// Mission-control: fleet of connected units, OTA jobs, release, alerts.

const DM_USER = { name: 'Saanvi Rao', email: 's.rao@arogyasync.com', role: 'admin' };

// Fleet stats
const DM_FLEET_STATS = {
  total: 1284,
  healthy: 1187,
  warning: 64,
  critical: 33,
  offline: 12,
  // Last 7 days
  healthySpark: [1180, 1183, 1175, 1188, 1192, 1186, 1187],
  warningSpark: [42, 51, 58, 63, 48, 55, 64],
  criticalSpark: [18, 22, 27, 31, 28, 30, 33],
};

// Release version distribution
const DM_RELEASE = [
  { version: 'v1.3.0', count: 712, color: '#06b6d4', latest: true },
  { version: 'v1.2.4', count: 348, color: '#0891b2' },
  { version: 'v1.2.0', count: 142, color: '#0e7490' },
  { version: 'v1.1.x', count: 67,  color: '#164e63' },
  { version: 'Other',  count: 15,  color: '#475569' },
];

// Hospital topology (for map view in OTA / Fleet detail)
const DM_HOSPITALS = [
  { id: 1, name: 'Apollo · Mumbai',     short: 'APO', devices: 142, healthy: 134, warning: 6, critical: 2 },
  { id: 2, name: 'AIIMS · Pune',         short: 'AII', devices: 88,  healthy: 86,  warning: 2, critical: 0 },
  { id: 3, name: 'Fortis · Bangalore',   short: 'FCC', devices: 67,  healthy: 60,  warning: 5, critical: 2 },
  { id: 4, name: 'Manipal · Delhi',      short: 'MAN', devices: 156, healthy: 142, warning: 9, critical: 5 },
  { id: 5, name: 'Max · Gurugram',       short: 'MAX', devices: 121, healthy: 118, warning: 2, critical: 1 },
  { id: 6, name: 'Medanta · Chennai',    short: 'MDT', devices: 94,  healthy: 91,  warning: 2, critical: 1 },
];

// Active devices (for table — sample of ~14)
const DM_DEVICES = [
  { id: 1, name: 'APO-RPI-0041', mac: 'B8:27:EB:42:81:01', hospital: 'Apollo · Mumbai',     ward: 'ICU 3F',     release: 'v1.3.0', health: 96, status: 'healthy',   cpu: 18, mem: 42, disk: 31, lastSeen: '8s' },
  { id: 2, name: 'APO-RPI-0042', mac: 'B8:27:EB:42:81:02', hospital: 'Apollo · Mumbai',     ward: 'ICU 3F',     release: 'v1.3.0', health: 94, status: 'healthy',   cpu: 22, mem: 38, disk: 28, lastSeen: '12s' },
  { id: 3, name: 'APO-RPI-0043', mac: 'B8:27:EB:42:81:03', hospital: 'Apollo · Mumbai',     ward: 'General 2F', release: 'v1.2.4', health: 72, status: 'warning',   cpu: 64, mem: 71, disk: 58, lastSeen: '18s' },
  { id: 4, name: 'AII-RPI-0118', mac: 'B8:27:EB:38:11:18', hospital: 'AIIMS · Pune',         ward: 'ICU',        release: 'v1.3.0', health: 91, status: 'healthy',   cpu: 28, mem: 48, disk: 34, lastSeen: '5s' },
  { id: 5, name: 'FCC-RPI-0008', mac: 'B8:27:EB:09:12:08', hospital: 'Fortis · Bangalore',   ward: 'Cardiac',    release: 'v1.2.0', health: 42, status: 'critical',  cpu: 88, mem: 92, disk: 79, lastSeen: '2m' },
  { id: 6, name: 'MAN-RPI-0244', mac: 'B8:27:EB:71:48:44', hospital: 'Manipal · Delhi',      ward: 'ICU 1A',     release: 'v1.3.0', health: 89, status: 'healthy',   cpu: 32, mem: 51, disk: 38, lastSeen: '4s' },
  { id: 7, name: 'MAN-RPI-0245', mac: 'B8:27:EB:71:48:45', hospital: 'Manipal · Delhi',      ward: 'ICU 1A',     release: 'v1.3.0', health: 95, status: 'healthy',   cpu: 20, mem: 41, disk: 30, lastSeen: '6s' },
  { id: 8, name: 'MAX-RPI-0083', mac: 'B8:27:EB:55:21:83', hospital: 'Max · Gurugram',       ward: 'Recovery',   release: 'v1.3.0', health: 92, status: 'healthy',   cpu: 24, mem: 39, disk: 36, lastSeen: '9s' },
  { id: 9, name: 'MAN-RPI-0246', mac: 'B8:27:EB:71:48:46', hospital: 'Manipal · Delhi',      ward: 'ICU 1B',     release: 'v1.2.4', health: 38, status: 'critical',  cpu: 94, mem: 88, disk: 91, lastSeen: '14m' },
  { id: 10,name: 'MDT-RPI-0021', mac: 'B8:27:EB:43:09:21', hospital: 'Medanta · Chennai',    ward: 'ICU 2F',     release: 'v1.3.0', health: 88, status: 'healthy',   cpu: 36, mem: 55, disk: 40, lastSeen: '3s' },
  { id: 11,name: 'APO-RPI-0048', mac: 'B8:27:EB:42:81:08', hospital: 'Apollo · Mumbai',     ward: 'Cardiac',    release: 'v1.2.4', health: 68, status: 'warning',   cpu: 58, mem: 67, disk: 49, lastSeen: '22s' },
  { id: 12,name: 'AII-RPI-0119', mac: 'B8:27:EB:38:11:19', hospital: 'AIIMS · Pune',         ward: 'General',    release: 'v1.3.0', health: 93, status: 'healthy',   cpu: 26, mem: 44, disk: 33, lastSeen: '11s' },
  { id: 13,name: 'FCC-RPI-0009', mac: 'B8:27:EB:09:12:09', hospital: 'Fortis · Bangalore',   ward: 'General',    release: 'v1.1.8', health: 0,  status: 'offline',    cpu: 0,  mem: 0,  disk: 0,  lastSeen: '6h 12m' },
  { id: 14,name: 'MAX-RPI-0084', mac: 'B8:27:EB:55:21:84', hospital: 'Max · Gurugram',       ward: 'ICU',        release: 'v1.3.0', health: 97, status: 'healthy',   cpu: 16, mem: 36, disk: 28, lastSeen: '4s' },
];

// OTA jobs
const DM_OTA_JOBS = [
  { id: 'OTA-0412', target: 'v1.3.0', startedAt: '2026-05-18 09:14', initiatedBy: 'Saanvi Rao', total: 412, completed: 119, inProgress: 287, failed: 6, status: 'in_progress' },
  { id: 'OTA-0411', target: 'v1.3.0', startedAt: '2026-05-17 16:42', initiatedBy: 'Saanvi Rao', total: 88,  completed: 87,  inProgress: 0, failed: 1, status: 'completed' },
  { id: 'OTA-0410', target: 'v1.3.0-rc.4', startedAt: '2026-05-17 11:08', initiatedBy: 'Marcus Lin', total: 24,  completed: 22,  inProgress: 0, failed: 2, status: 'completed' },
  { id: 'OTA-0409', target: 'v1.2.4', startedAt: '2026-05-16 14:30', initiatedBy: 'Saanvi Rao', total: 156, completed: 154, inProgress: 0, failed: 2, status: 'completed' },
  { id: 'OTA-0408', target: 'v1.2.4', startedAt: '2026-05-16 10:18', initiatedBy: 'Marcus Lin', total: 67,  completed: 30,  inProgress: 0, failed: 37, status: 'failed' },
  { id: 'OTA-0407', target: 'v1.2.4', startedAt: '2026-05-15 17:55', initiatedBy: 'Saanvi Rao', total: 348, completed: 346, inProgress: 0, failed: 2, status: 'completed' },
];

// Release catalog
const DM_RELEASE_CATALOG = [
  { id: 'FW-013', version: 'v1.3.0',       unitType: 'RPI-Zero-2W', size: '38.2 MB', uploaded: '2026-05-10', approved: true,  approvedAt: '2026-05-12' },
  { id: 'FW-014', version: 'v1.3.0-rc.4',  unitType: 'RPI-Zero-2W', size: '38.1 MB', uploaded: '2026-05-08', approved: true,  approvedAt: '2026-05-09' },
  { id: 'FW-015', version: 'v1.3.1-rc.1',  unitType: 'RPI-Zero-2W', size: '38.4 MB', uploaded: '2026-05-17', approved: false },
  { id: 'FW-012', version: 'v1.2.4',       unitType: 'RPI-Zero-2W', size: '37.8 MB', uploaded: '2026-04-22', approved: true,  approvedAt: '2026-04-24' },
  { id: 'FW-011', version: 'v1.2.0',       unitType: 'RPI-Zero-2W', size: '37.2 MB', uploaded: '2026-04-01', approved: true,  approvedAt: '2026-04-03' },
];

// Alerts feed
const DM_ALERTS = [
  { id: 1, sev: 'critical', device: 'FCC-RPI-0008', hospital: 'Fortis · Bangalore', msg: 'CPU sustained > 90% for 8 minutes', time: '2m ago' },
  { id: 2, sev: 'critical', device: 'MAN-RPI-0246', hospital: 'Manipal · Delhi',    msg: 'Disk usage 91% — log rotation failing', time: '14m ago' },
  { id: 3, sev: 'warning',  device: 'APO-RPI-0043', hospital: 'Apollo · Mumbai',    msg: 'Memory pressure rising', time: '32m ago' },
  { id: 4, sev: 'info',     device: 'FCC-RPI-0009', hospital: 'Fortis · Bangalore', msg: 'Device offline for 6h 12m', time: '6h ago' },
];

// Health metrics — for sparkline mini-chart in cards
function genMetric(samples, base, range) {
  return Array.from({ length: samples }, () => Math.max(0, Math.min(100, base + (Math.random() - 0.5) * range)));
}
const DM_HEALTH_HISTORY = {
  cpu: genMetric(48, 35, 30),
  memory: genMetric(48, 52, 24),
  disk: genMetric(48, 38, 8),
  queue: genMetric(48, 12, 16),
};

// Map node positions — for hospital topology view
const DM_MAP_NODES = [
  { id: 1, x: 22, y: 35, label: 'APO', size: 142, health: 'mixed' },
  { id: 2, x: 38, y: 28, label: 'AII', size: 88,  health: 'healthy' },
  { id: 3, x: 26, y: 65, label: 'FCC', size: 67,  health: 'critical' },
  { id: 4, x: 50, y: 18, label: 'MAN', size: 156, health: 'warning' },
  { id: 5, x: 54, y: 24, label: 'MAX', size: 121, health: 'healthy' },
  { id: 6, x: 40, y: 70, label: 'MDT', size: 94,  health: 'healthy' },
];

Object.assign(window, {
  DM_USER, DM_FLEET_STATS, DM_RELEASE, DM_HOSPITALS, DM_DEVICES,
  DM_OTA_JOBS, DM_RELEASE_CATALOG, DM_ALERTS, DM_HEALTH_HISTORY, DM_MAP_NODES,
});
