// ESI COLLECTIONS — Extended Data Layer
// Merges into ESI_DATA._default.collectionsExt

(function() {
  const d = window.ESI_DATA._default;

  d.collectionsExt = {
    kpis: {
      totalJobs: 6, activeJobs: 3, completedJobs: 3, scheduledJobs: 2,
      totalVolumeGB: 516.8, collectedVolumeGB: 182.0,
      totalDocs: 880_000, collectedDocs: 584_000,
      custodiansCovered: 12, custodiansComplete: 4,
      vendorsEngaged: 5, avgCycleTimeDays: 6.2,
      errorRate: 0.4, retryQueue: 1,
      compliancePct: 100, chainCoverage: 100,
    },

    // Extended job records (supplements data.collections)
    jobs: [
      {
        id: 'COL-8421', source: 'Microsoft 365 (Exchange)', sourceType: 'Email',
        custodian: '4 custodians (batch)', custodianIds: ['Helen Bishop','Marcus Pryor','Julia Matsumoto','David Okonkwo'],
        started: '2026-04-18', eta: '2026-04-23', completedOn: null,
        vendor: 'Internal — Relativity One', vendorId: 'VND-01',
        volumeGB: 112.4, docCount: 298_000, collectedGB: 68.2, collectedDocs: 182_000,
        status: 'In Progress', method: 'Graph API — targeted date range',
        dateRangeFrom: '2020-01-01', dateRangeTo: '2024-12-31',
        keywords: ['Apex','Meridian','pricing','consultant','agreement'],
        chainId: 'CC-1842', errorCount: 0, retries: 0,
        progressPct: 61,
        notes: 'Graph API targeted date range 2020-01 to 2024-12. Throttling managed via exponential backoff.',
        legalHoldId: 'LH-2024-008', approvedBy: 'M. Kirkland', approvedOn: '2026-04-15',
      },
      {
        id: 'COL-8420', source: 'Mobile Devices (iPhone)', sourceType: 'Mobile',
        custodian: '3 additional custodians', custodianIds: ['James Harrington','Priya Raman','Felix Wong'],
        started: '2026-04-16', eta: '2026-04-22', completedOn: null,
        vendor: 'Cellebrite Premium', vendorId: 'VND-04',
        volumeGB: 38.4, docCount: 98_000, collectedGB: 38.4, collectedDocs: 98_000,
        status: 'In Progress', method: 'Full-file-system imaging',
        dateRangeFrom: null, dateRangeTo: null,
        keywords: [],
        chainId: 'CC-1841', errorCount: 0, retries: 0,
        progressPct: 100,
        notes: 'FFS imaging complete. Awaiting transfer to Relativity staging.',
        legalHoldId: 'LH-2024-008', approvedBy: 'M. Kirkland', approvedOn: '2026-04-14',
      },
      {
        id: 'COL-8419', source: 'Google Workspace (Gmail)', sourceType: 'Email',
        custodian: 'Arnav Iyer', custodianIds: ['Arnav Iyer'],
        started: '2026-04-14', eta: '2026-04-18', completedOn: '2026-04-18',
        vendor: 'Internal — Relativity One', vendorId: 'VND-01',
        volumeGB: 24.8, docCount: 48_000, collectedGB: 24.8, collectedDocs: 48_000,
        status: 'Complete ok', method: 'Google Vault export',
        dateRangeFrom: '2019-01-01', dateRangeTo: '2026-04-14',
        keywords: ['Apex','Singapore','APAC','consultant'],
        chainId: 'CC-1840', errorCount: 0, retries: 0,
        progressPct: 100,
        notes: 'Google Vault export via OAuth. Schema validated; 0 records rejected.',
        legalHoldId: 'LH-2024-008', approvedBy: 'L. Torres', approvedOn: '2026-04-12',
      },
      {
        id: 'COL-8418', source: 'Archive tapes (legacy)', sourceType: 'Archive',
        custodian: 'Former CFO mailbox 2020-2023', custodianIds: ['Karen Osei'],
        started: '2026-04-10', eta: '2026-04-28', completedOn: null,
        vendor: 'Iron Mountain', vendorId: 'VND-05',
        volumeGB: 184.2, docCount: null, collectedGB: 0, collectedDocs: 0,
        status: 'In Progress', method: 'Tape restore to PST',
        dateRangeFrom: '2020-01-01', dateRangeTo: '2023-12-31',
        keywords: ['APAC','pricing','wire','transfer'],
        chainId: 'CC-1839', errorCount: 0, retries: 0,
        progressPct: 18,
        notes: 'Tape barcode 9284/9285/9286 confirmed at vault. Restore in progress.',
        legalHoldId: 'LH-2024-008', approvedBy: 'M. Kirkland', approvedOn: '2026-04-08',
      },
      {
        id: 'COL-8417', source: 'WhatsApp', sourceType: 'Chat',
        custodian: '3 APAC custodians', custodianIds: ['Karen Osei','Arnav Iyer','Simon Okafor'],
        started: '2026-04-08', eta: '2026-04-12', completedOn: '2026-04-12',
        vendor: 'Smarsh', vendorId: 'VND-06',
        volumeGB: 8.4, docCount: 24_000, collectedGB: 8.4, collectedDocs: 24_000,
        status: 'Complete ok', method: 'Smarsh enterprise archive export',
        dateRangeFrom: '2021-01-01', dateRangeTo: '2026-04-08',
        keywords: [],
        chainId: 'CC-1838', errorCount: 0, retries: 0,
        progressPct: 100,
        notes: 'Smarsh enterprise export + JSON schema validation (3 custodians in APAC).',
        legalHoldId: 'LH-2024-008', approvedBy: 'L. Torres', approvedOn: '2026-04-06',
      },
      {
        id: 'COL-8416', source: 'SharePoint (Corporate)', sourceType: 'File Share',
        custodian: '14 matter-scoped sites', custodianIds: [],
        started: '2026-04-02', eta: '2026-04-14', completedOn: '2026-04-14',
        vendor: 'Internal', vendorId: 'VND-01',
        volumeGB: 148.6, docCount: 412_000, collectedGB: 148.6, collectedDocs: 412_000,
        status: 'Complete ok', method: 'Graph API scoped collection',
        dateRangeFrom: '2018-01-01', dateRangeTo: '2026-04-02',
        keywords: [],
        chainId: 'CC-1837', errorCount: 0, retries: 0,
        progressPct: 100,
        notes: 'Scoped API collection across 14 matter-bound SharePoint sites.',
        legalHoldId: 'LH-2024-008', approvedBy: 'S. Chen', approvedOn: '2026-03-28',
      },
    ],

    // Scheduled upcoming collections
    scheduled: [
      { id: 'COL-8423', source: 'Microsoft Teams (supplemental)', sourceType: 'Chat', custodian: 'Thomas Blackwell', scheduledDate: '2026-04-28', vendor: 'Internal', estimatedGB: 12.4, method: 'Graph API — compliance export', approvedBy: 'M. Kirkland', status: 'Scheduled', legalHoldId: 'LH-2024-008' },
      { id: 'COL-8422', source: 'Salesforce (supplemental)', sourceType: 'SaaS', custodian: 'Priya Raman + Elena Vasquez', scheduledDate: '2026-05-02', vendor: 'Internal', estimatedGB: 8.2, method: 'Bulk API v2', approvedBy: 'L. Torres', status: 'Scheduled', legalHoldId: 'LH-2024-008' },
    ],

    // Per-custodian collection coverage
    custodianCoverage: [
      { name: 'Helen Bishop',     role: 'Former CEO',       sourcesTotal: 6, sourcesCollected: 5, sourcesInProgress: 1, volumeGB: 184.2, pct: 83, status: 'In Progress' },
      { name: 'Karen Osei',       role: 'Former CFO — APAC',sourcesTotal: 4, sourcesCollected: 2, sourcesInProgress: 1, volumeGB: 92.4,  pct: 62, status: 'In Progress' },
      { name: 'Marcus Pryor',     role: 'GC',               sourcesTotal: 5, sourcesCollected: 4, sourcesInProgress: 1, volumeGB: 142.8, pct: 80, status: 'In Progress' },
      { name: 'James Harrington', role: 'CEO Meridian',     sourcesTotal: 6, sourcesCollected: 5, sourcesInProgress: 1, volumeGB: 218.6, pct: 83, status: 'In Progress' },
      { name: 'Julia Matsumoto',  role: 'Head of M&A',      sourcesTotal: 4, sourcesCollected: 4, sourcesInProgress: 0, volumeGB: 68.1,  pct: 100, status: 'Complete' },
      { name: 'David Okonkwo',    role: 'Deputy CFO',       sourcesTotal: 3, sourcesCollected: 3, sourcesInProgress: 0, volumeGB: 52.4,  pct: 100, status: 'Complete' },
      { name: 'Thomas Blackwell', role: 'Chief Engineer',   sourcesTotal: 6, sourcesCollected: 5, sourcesInProgress: 0, sourcesScheduled: 1, volumeGB: 148.4, pct: 83, status: 'Partial' },
      { name: 'Priya Raman',      role: 'VP Pricing',       sourcesTotal: 4, sourcesCollected: 3, sourcesInProgress: 1, volumeGB: 86.2,  pct: 75, status: 'In Progress' },
      { name: 'Arnav Iyer',       role: 'APAC Head',        sourcesTotal: 4, sourcesCollected: 4, sourcesInProgress: 0, volumeGB: 142.6, pct: 100, status: 'Complete' },
      { name: 'Elena Vasquez',    role: 'VP Compliance',    sourcesTotal: 3, sourcesCollected: 2, sourcesInProgress: 0, sourcesScheduled: 1, volumeGB: 78.4, pct: 67, status: 'Partial' },
      { name: 'Felix Wong',       role: 'Dir. Operations',  sourcesTotal: 4, sourcesCollected: 3, sourcesInProgress: 1, volumeGB: 96.8,  pct: 75, status: 'In Progress' },
      { name: 'Simon Okafor',     role: 'Sterling GC',      sourcesTotal: 4, sourcesCollected: 2, sourcesInProgress: 0, volumeGB: 168.4, pct: 50, status: 'Partial' },
    ],

    // Scope definitions
    scope: [
      { id: 'SC-01', name: 'Core custodian email — date-scoped', sources: ['Microsoft 365 (Exchange)','Google Workspace (Gmail)'], custodians: 12, dateFrom: '2020-01-01', dateTo: '2026-04-18', keywords: ['Apex','Meridian','pricing','consultant','agreement','APAC','Singapore'], exclusions: ['newsletters','automated alerts'], estimatedGB: 450.4, status: 'Active', approvedBy: 'M. Kirkland', approvedOn: '2026-02-01' },
      { id: 'SC-02', name: 'Cloud collaboration & messaging', sources: ['Microsoft Teams','Slack','WhatsApp','Zoom'], custodians: 10, dateFrom: '2021-01-01', dateTo: '2026-04-18', keywords: [], exclusions: ['#general','#random','automated bots'], estimatedGB: 203.6, status: 'Active', approvedBy: 'M. Kirkland', approvedOn: '2026-02-01' },
      { id: 'SC-03', name: 'File shares & document repositories', sources: ['SharePoint (Corporate)','OneDrive','Box.com','iManage (DMS)'], custodians: 12, dateFrom: '2018-01-01', dateTo: '2026-04-18', keywords: [], exclusions: ['temp files','system folders'], estimatedGB: 771.6, status: 'Active', approvedBy: 'L. Torres', approvedOn: '2026-02-08' },
      { id: 'SC-04', name: 'Mobile devices — full-file-system', sources: ['Mobile Devices (iPhone)','Mobile Devices (Android)'], custodians: 10, dateFrom: null, dateTo: null, keywords: [], exclusions: ['media library > 50MB'], estimatedGB: 146.6, status: 'Active', approvedBy: 'M. Kirkland', approvedOn: '2026-03-01' },
      { id: 'SC-05', name: 'Financial & ERP systems', sources: ['SAP ERP','Salesforce','Intralinks VDR'], custodians: null, dateFrom: '2019-01-01', dateTo: '2026-04-18', keywords: ['wire','transfer','consultant fee','agreement'], exclusions: [], estimatedGB: 274.8, status: 'Active', approvedBy: 'M. Kirkland', approvedOn: '2026-02-15' },
      { id: 'SC-06', name: 'Legacy archive restoration', sources: ['Archive tapes (legacy)','PST/OST export'], custodians: null, dateFrom: '2018-01-01', dateTo: '2023-12-31', keywords: ['Karen Osei','APAC','pricing'], exclusions: [], estimatedGB: 456.2, status: 'Active', approvedBy: 'M. Kirkland', approvedOn: '2026-03-15' },
    ],

    // Vendor performance
    vendorPerformance: [
      { vendorId: 'VND-01', name: 'Internal — Relativity One', jobsTotal: 3, jobsComplete: 2, avgCycleDays: 5.8, dataRateMBs: 18.4, errorRate: 0.0, slaCompliance: 100, lastJob: 'COL-8421', cost: 0, notes: 'Primary internal collection engine' },
      { vendorId: 'VND-04', name: 'Cellebrite Premium', jobsTotal: 1, jobsComplete: 0, avgCycleDays: 6.0, dataRateMBs: null, errorRate: 0.0, slaCompliance: 100, lastJob: 'COL-8420', cost: 8_400, notes: 'Mobile FFS imaging — awaiting transfer' },
      { vendorId: 'VND-05', name: 'Iron Mountain', jobsTotal: 1, jobsComplete: 0, avgCycleDays: 18.0, dataRateMBs: null, errorRate: 0.0, slaCompliance: 94, lastJob: 'COL-8418', cost: 4_800, notes: 'Tape restore SLA 21 days; on track' },
      { vendorId: 'VND-06', name: 'Smarsh', jobsTotal: 1, jobsComplete: 1, avgCycleDays: 4.0, dataRateMBs: 24.2, errorRate: 0.0, slaCompliance: 100, lastJob: 'COL-8417', cost: 3_200, notes: 'Fastest turnaround this matter' },
      { vendorId: 'VND-07', name: 'Consilio', jobsTotal: 0, jobsComplete: 0, avgCycleDays: null, dataRateMBs: null, errorRate: null, slaCompliance: null, lastJob: null, cost: 0, notes: 'On standby for overflow collections' },
    ],

    // Errors & retries
    errors: [
      { id: 'ERR-042', jobId: 'COL-8418', ts: '2026-04-10 14:22', type: 'API Timeout', detail: 'Iron Mountain vault API timed out after 30s — auto-retry scheduled', severity: 'warn', resolved: true, resolvedOn: '2026-04-10 14:38', resolution: 'Auto-retry succeeded after 16 min' },
      { id: 'ERR-041', jobId: 'COL-8421', ts: '2026-04-18 11:04', type: 'Throttle limit hit', detail: 'MS Graph API throttled — 429 Too Many Requests on mailbox M. Pryor', severity: 'info', resolved: true, resolvedOn: '2026-04-18 11:22', resolution: 'Exponential backoff applied; collection resumed' },
      { id: 'ERR-040', jobId: 'COL-8419', ts: '2026-04-14 09:42', type: 'Schema mismatch', detail: 'Google Vault export missing 3 attachment records — schema v2 incompatibility', severity: 'warn', resolved: true, resolvedOn: '2026-04-14 10:18', resolution: 'Re-exported with schema v3; all records reconciled' },
    ],

    // Audit trail
    audit: [
      { id: 'CAU-088', ts: '2026-04-21 08:14', actor: 'S. Chen', action: 'JOB_UPDATE', target: 'COL-8421', detail: '61% progress — 182K docs ingested of 298K est.', severity: 'info', sig: 'HMAC ok' },
      { id: 'CAU-087', ts: '2026-04-20 16:42', actor: 'System', action: 'SCOPE_VERIFY', target: 'SC-01', detail: 'Custodian date-range scope validated against hold LH-2024-008', severity: 'info', sig: 'HMAC ok' },
      { id: 'CAU-086', ts: '2026-04-18 10:58', actor: 'S. Chen', action: 'JOB_START', target: 'COL-8421', detail: 'Collection job started — Exchange 4-custodian batch', severity: 'info', sig: 'HMAC ok' },
      { id: 'CAU-085', ts: '2026-04-18 10:22', actor: 'M. Kirkland', action: 'JOB_APPROVE', target: 'COL-8421', detail: 'Collection approved — LH-2024-008 in scope confirmed', severity: 'info', sig: 'PGP ok' },
      { id: 'CAU-084', ts: '2026-04-17 14:20', actor: 'R. Ozawa', action: 'JOB_COMPLETE', target: 'COL-8420', detail: 'Cellebrite FFS imaging complete — 38.4 GB · hash verified', severity: 'info', sig: 'HMAC ok' },
      { id: 'CAU-083', ts: '2026-04-14 18:02', actor: 'L. Torres', action: 'JOB_COMPLETE', target: 'COL-8419', detail: 'Google Vault export complete — 24.8 GB · 48K docs · schema validated', severity: 'info', sig: 'HMAC ok' },
      { id: 'CAU-082', ts: '2026-04-14 09:42', actor: 'System', action: 'ERROR_RESOLVED', target: 'ERR-040', detail: 'Schema mismatch resolved — re-export with v3 schema', severity: 'warn', sig: 'HMAC ok' },
      { id: 'CAU-081', ts: '2026-04-12 11:30', actor: 'L. Torres', action: 'JOB_COMPLETE', target: 'COL-8417', detail: 'Smarsh WhatsApp export complete — 8.4 GB · 24K docs', severity: 'info', sig: 'HMAC ok' },
      { id: 'CAU-080', ts: '2026-04-10 14:38', actor: 'System', action: 'ERROR_RESOLVED', target: 'ERR-042', detail: 'Iron Mountain API retry succeeded', severity: 'info', sig: 'HMAC ok' },
      { id: 'CAU-079', ts: '2026-04-10 08:00', actor: 'J. Pike', action: 'JOB_START', target: 'COL-8418', detail: 'Tape restore initiated — Iron Mountain vault #9284/9285/9286', severity: 'info', sig: 'HMAC ok' },
      { id: 'CAU-078', ts: '2026-04-08 11:00', actor: 'M. Kirkland', action: 'SCOPE_APPROVE', target: 'SC-06', detail: 'Legacy archive scope approved — date range 2018-2023', severity: 'info', sig: 'PGP ok' },
      { id: 'CAU-077', ts: '2026-04-02 11:48', actor: 'S. Chen', action: 'JOB_COMPLETE', target: 'COL-8416', detail: 'SharePoint collection complete — 148.6 GB · 412K docs', severity: 'info', sig: 'HMAC ok' },
    ],
  };
})();
