// Demo data for the FOI prototype.
// MATs are a fictionalised slice modelled on GIAS shape (group_uid, name, region, schools count, contact).
// FOI requests cover a range of statuses and recipient types.

const REGIONS = [
  "North East", "North West", "Yorkshire & Humber",
  "East Midlands", "West Midlands", "East of England",
  "London", "South East", "South West"
];

const MATS = [
  { uid: "TR-10421", name: "Northern Lights Learning Trust",        region: "North East",          schools: 14, town: "Newcastle",   pupils: 8420,  contact: "info@nlltrust.example.org",        contactName: "Sarah Whelan",      contactRole: "Trust Secretary",      verified: true,  source: "Trust website /contact" },
  { uid: "TR-10733", name: "Pennine Academies",                     region: "North West",          schools:  9, town: "Bolton",      pupils: 5210,  contact: "foi@pennine-academies.example",     contactName: "—",                  contactRole: "FOI inbox",            verified: true,  source: "Trust website /foi" },
  { uid: "TR-10812", name: "Mersey Bridge Education Trust",         region: "North West",          schools: 22, town: "Liverpool",   pupils: 13980, contact: "governance@merseybridge.example",   contactName: "David Aitchison",    contactRole: "Director of Governance", verified: true,  source: "Companies House filing" },
  { uid: "TR-11104", name: "White Rose Academies Trust",            region: "Yorkshire & Humber",  schools: 11, town: "Leeds",       pupils: 7340,  contact: "office@whiterose-mat.example",      contactName: "Priya Shah",         contactRole: "Office Manager",       verified: false, source: "Scraped — confidence 0.71" },
  { uid: "TR-11290", name: "Humber Coast Federation",               region: "Yorkshire & Humber",  schools:  6, town: "Hull",        pupils: 3120,  contact: "ceo@humbercoast.example",           contactName: "Mark Reilly",        contactRole: "CEO",                  verified: false, source: "Scraped — confidence 0.62" },
  { uid: "TR-11540", name: "Trent Vale Schools Partnership",        region: "East Midlands",       schools:  8, town: "Nottingham",  pupils: 4610,  contact: "admin@trentvale.example",           contactName: "Helen Booth",        contactRole: "Trust Administrator",  verified: true,  source: "Trust website footer" },
  { uid: "TR-11782", name: "Black Country Academies",               region: "West Midlands",       schools: 17, town: "Wolverhampton", pupils: 10880, contact: "info@blackcountry-academies.example", contactName: "—",               contactRole: "General enquiries",    verified: true,  source: "Trust website /contact" },
  { uid: "TR-11801", name: "Avon & Severn Learning Trust",          region: "South West",          schools: 13, town: "Bristol",     pupils: 7990,  contact: "foi@avonsevern.example",            contactName: "Jonathan Pike",      contactRole: "Data Protection Officer", verified: true,  source: "Privacy notice" },
  { uid: "TR-11930", name: "Estuary Schools Trust",                 region: "East of England",     schools: 19, town: "Southend",    pupils: 11440, contact: "trust@estuary-schools.example",     contactName: "Rachel Ngozi",       contactRole: "Chief of Staff",       verified: true,  source: "Trust website /trust-team" },
  { uid: "TR-12011", name: "Capital Horizons Academy Trust",        region: "London",              schools: 26, town: "Croydon",     pupils: 17220, contact: "foi-requests@capitalhorizons.example", contactName: "—",              contactRole: "FOI inbox",            verified: true,  source: "Publication scheme" },
  { uid: "TR-12188", name: "Thames Gateway Education Trust",        region: "London",              schools: 12, town: "Barking",     pupils: 7800,  contact: "info@thamesgateway-edu.example",    contactName: "Yusuf Karim",        contactRole: "Trust Manager",        verified: false, source: "Scraped — confidence 0.58" },
  { uid: "TR-12290", name: "Weald Federation",                      region: "South East",          schools:  7, town: "Tunbridge",   pupils: 4080,  contact: "office@wealdfed.example",           contactName: "Claire Holmes",      contactRole: "Office Manager",       verified: true,  source: "Trust website /contact" },
  { uid: "TR-12404", name: "Solent Academies",                      region: "South East",          schools: 10, town: "Portsmouth",  pupils: 6120,  contact: "governance@solent-academies.example", contactName: "—",                contactRole: "Governance team",      verified: true,  source: "Trust website /governance" },
  { uid: "TR-12511", name: "Dartmoor Learning Co-operative",        region: "South West",          schools:  5, town: "Plymouth",    pupils: 2680,  contact: "trust@dartmoorlc.example",          contactName: "Owen Pritchard",     contactRole: "Director of Operations", verified: false, source: "Scraped — confidence 0.49" },
  { uid: "TR-12640", name: "Tyne Bridge Federation",                region: "North East",          schools:  8, town: "Sunderland",  pupils: 4310,  contact: "info@tynebridge-fed.example",       contactName: "Marian Edwards",     contactRole: "Trust Clerk",          verified: true,  source: "Trust website /contact" },
  { uid: "TR-12777", name: "Greater Manchester Education Trust",    region: "North West",          schools: 21, town: "Manchester",  pupils: 13110, contact: "foi@gmet.example",                  contactName: "—",                  contactRole: "FOI inbox",            verified: true,  source: "Publication scheme" },
  { uid: "TR-12810", name: "Anglia Heritage Academies",             region: "East of England",     schools: 14, town: "Norwich",     pupils: 8540,  contact: "admin@angliaheritage.example",      contactName: "Esme Tomlinson",     contactRole: "Trust Administrator",  verified: true,  source: "Trust website footer" },
  { uid: "TR-12977", name: "Severnvale Schools Group",              region: "West Midlands",       schools:  9, town: "Worcester",   pupils: 5240,  contact: "office@severnvale.example",         contactName: "Daniel Okafor",      contactRole: "Office Manager",       verified: false, source: "Scraped — confidence 0.66" },
  { uid: "TR-13002", name: "Cornish Coastal Academies",             region: "South West",          schools:  6, town: "Truro",       pupils: 3210,  contact: "trust@cornishcoastal.example",      contactName: "Bethan Trevithick",  contactRole: "Trust Manager",        verified: true,  source: "Trust website /our-team" },
  { uid: "TR-13144", name: "Chiltern Edge Learning Trust",          region: "South East",          schools: 11, town: "High Wycombe", pupils: 6850, contact: "foi@chilternedge.example",          contactName: "—",                  contactRole: "FOI inbox",            verified: true,  source: "Publication scheme" }
];

// FOI requests across the lifecycle.
// "dispatched" is days ago. Daysago is used to derive the working-day countdown.
const today = new Date('2026-05-28');
function daysAgo(n) {
  const d = new Date(today);
  d.setDate(d.getDate() - n);
  return d.toISOString().slice(0, 10);
}

const REQUESTS = [
  {
    id: "FOI-2026-0114",
    title: "Use of agency staff in primary schools 2024–25",
    recipientType: "DfE",
    recipientName: "Department for Education",
    channel: "WhatDoTheyKnow API",
    status: "overdue",
    sentOn: daysAgo(28),
    workingDaysElapsed: 22,
    deadline: daysAgo(28 - 28),
    owner: "R. Davies",
    tags: ["staffing", "agency"],
    replies: 1,
    summary: "Requested monthly spend on supply agency staff broken down by region for academic year 2024–25.",
  },
  {
    id: "FOI-2026-0118",
    title: "CEO and executive pay across MATs",
    recipientType: "MAT batch",
    recipientName: "42 trusts",
    channel: "Email — SMTP",
    status: "in-progress",
    sentOn: daysAgo(14),
    workingDaysElapsed: 10,
    deadline: daysAgo(14 - 28),
    owner: "A. Choudhury",
    tags: ["pay", "executive"],
    replies: 17,
    summary: "Salary bands of all trust executives earning over £100k, plus expense claims for 2024–25.",
  },
  {
    id: "FOI-2026-0121",
    title: "SEND tribunal outcomes Q1 2026",
    recipientType: "DfE",
    recipientName: "Department for Education",
    channel: "WhatDoTheyKnow API",
    status: "acknowledged",
    sentOn: daysAgo(6),
    workingDaysElapsed: 4,
    deadline: daysAgo(6 - 28),
    owner: "R. Davies",
    tags: ["SEND", "tribunals"],
    replies: 1,
    summary: "Number of SEND tribunal cases by LA, with outcomes and average duration.",
  },
  {
    id: "FOI-2026-0124",
    title: "Off-rolling — pupils removed before Y11 census",
    recipientType: "MAT batch",
    recipientName: "18 trusts",
    channel: "Email — SMTP",
    status: "fulfilled",
    sentOn: daysAgo(36),
    workingDaysElapsed: 20,
    deadline: daysAgo(36 - 28),
    owner: "M. Patel",
    tags: ["off-rolling", "exclusions"],
    replies: 18,
    summary: "Pupils removed from roll between Years 10 and 11 over the last three academic years.",
  },
  {
    id: "FOI-2026-0125",
    title: "Teacher vacancies — Sept 2025 census",
    recipientType: "DfE",
    recipientName: "Department for Education",
    channel: "WhatDoTheyKnow API",
    status: "fulfilled",
    sentOn: daysAgo(44),
    workingDaysElapsed: 20,
    deadline: daysAgo(44 - 28),
    owner: "A. Choudhury",
    tags: ["recruitment"],
    replies: 2,
    summary: "Unfilled teacher vacancies on the September 2025 school workforce census by phase and subject.",
  },
  {
    id: "FOI-2026-0126",
    title: "Behaviour hub schools — invitation criteria",
    recipientType: "DfE",
    recipientName: "Department for Education",
    channel: "WhatDoTheyKnow API",
    status: "refused",
    sentOn: daysAgo(52),
    workingDaysElapsed: 20,
    deadline: daysAgo(52 - 28),
    owner: "R. Davies",
    tags: ["behaviour"],
    replies: 1,
    summary: "Internal criteria used to invite schools into the Behaviour Hubs programme. Refused — s.35(1)(a).",
  },
  {
    id: "FOI-2026-0128",
    title: "Capital funding allocations to MATs 2025–26",
    recipientType: "DfE",
    recipientName: "Department for Education",
    channel: "WhatDoTheyKnow API",
    status: "draft",
    sentOn: null,
    workingDaysElapsed: 0,
    deadline: null,
    owner: "M. Patel",
    tags: ["capital", "funding"],
    replies: 0,
    summary: "Draft — not yet sent.",
  },
  {
    id: "FOI-2026-0129",
    title: "Internal review — Behaviour hub refusal",
    recipientType: "DfE",
    recipientName: "Department for Education",
    channel: "WhatDoTheyKnow API",
    status: "internal-review",
    sentOn: daysAgo(3),
    workingDaysElapsed: 2,
    deadline: daysAgo(3 - 28),
    owner: "R. Davies",
    tags: ["behaviour", "review"],
    replies: 0,
    summary: "Internal review of refusal in FOI-2026-0126 under s.35(1)(a).",
  }
];

const STATUS_META = {
  "draft":           { label: "Draft",           tone: "neutral" },
  "queued":          { label: "Queued",          tone: "neutral" },
  "sent":            { label: "Sent",            tone: "info" },
  "acknowledged":    { label: "Acknowledged",    tone: "info" },
  "in-progress":     { label: "In progress",     tone: "info" },
  "overdue":         { label: "Overdue",         tone: "danger" },
  "fulfilled":       { label: "Fulfilled",       tone: "ok" },
  "partial":         { label: "Partial",         tone: "warn" },
  "refused":         { label: "Refused",         tone: "warn" },
  "internal-review": { label: "Internal review", tone: "warn" }
};

// Inbox — emails / WDTK replies received
const INBOX = [
  {
    id: "MSG-3041",
    requestId: "FOI-2026-0118",
    from: "governance@merseybridge.example",
    fromName: "Mersey Bridge Education Trust",
    subject: "Re: FOI request — Executive pay 2024–25 [TR-10812]",
    receivedAt: "2026-05-26 14:12",
    extracted: {
      acknowledgement: true,
      responseClassification: "Acknowledged — substantive reply by 12 June",
      keyFields: [
        { k: "Executives over £100k", v: "4" },
        { k: "Highest band",          v: "£170,000–£175,000" },
        { k: "Expense total 2024–25", v: "£18,420.55" }
      ],
      confidence: 0.86,
      personalDataFlags: ["Named individual: David Aitchison (Director of Governance)"]
    }
  },
  {
    id: "MSG-3042",
    requestId: "FOI-2026-0118",
    from: "foi@pennine-academies.example",
    fromName: "Pennine Academies",
    subject: "FOI response — Executive Pay (your ref FOI-2026-0118)",
    receivedAt: "2026-05-26 09:48",
    extracted: {
      acknowledgement: false,
      responseClassification: "Full response — fulfilled",
      keyFields: [
        { k: "Executives over £100k", v: "2" },
        { k: "Highest band",          v: "£135,000–£140,000" },
        { k: "Expense total 2024–25", v: "£6,210.80" }
      ],
      confidence: 0.93,
      personalDataFlags: []
    }
  },
  {
    id: "MSG-3043",
    requestId: "FOI-2026-0114",
    from: "foi-requests@education.gov.uk",
    fromName: "DfE FOI Team",
    subject: "Response — Agency staff spend 2024–25 (DfE/2026/0094)",
    receivedAt: "2026-05-25 16:01",
    extracted: {
      acknowledgement: false,
      responseClassification: "Partial — section 12 cost limit invoked for one part",
      keyFields: [
        { k: "Total spend 2024–25",  v: "£1.42bn" },
        { k: "Region breakdown",     v: "Provided (Annex A)" },
        { k: "Monthly trend data",   v: "Refused — s.12(1)" }
      ],
      confidence: 0.81,
      personalDataFlags: []
    }
  },
  {
    id: "MSG-3044",
    requestId: "FOI-2026-0118",
    from: "info@nlltrust.example.org",
    fromName: "Northern Lights Learning Trust",
    subject: "Acknowledgement — your FOI of 14 May",
    receivedAt: "2026-05-24 11:30",
    extracted: {
      acknowledgement: true,
      responseClassification: "Acknowledged — will respond within 20 working days",
      keyFields: [],
      confidence: 0.95,
      personalDataFlags: ["Named individual: Sarah Whelan (Trust Secretary)"]
    }
  }
];

const AUDIT = [
  { t: "2026-05-28 09:14", who: "R. Davies",    action: "Opened request FOI-2026-0114" },
  { t: "2026-05-28 08:52", who: "system",        action: "LLM extraction completed for MSG-3041 (Anthropic claude-haiku-4)" },
  { t: "2026-05-28 08:51", who: "system",        action: "Inbound mail received from governance@merseybridge.example" },
  { t: "2026-05-27 17:09", who: "A. Choudhury", action: "Dispatched FOI-2026-0118 to 42 trusts (SMTP, batched 8/min)" },
  { t: "2026-05-27 17:08", who: "A. Choudhury", action: "Approved redaction pass — 3 personal names masked" },
  { t: "2026-05-27 16:55", who: "A. Choudhury", action: "Created FOI-2026-0118 from template ‘Executive pay’" },
  { t: "2026-05-26 12:02", who: "system",        action: "WDTK API: request id 1842931 acknowledged (ref DfE/2026/0094)" },
  { t: "2026-05-25 10:30", who: "M. Patel",     action: "Marked FOI-2026-0124 as fulfilled (18/18 replies)" }
];

const TEMPLATES = [
  { id: "TPL-01", name: "Executive pay (MAT)",          uses: 14, lastUsed: "2026-05-27" },
  { id: "TPL-02", name: "Off-rolling (MAT)",            uses:  9, lastUsed: "2026-04-18" },
  { id: "TPL-03", name: "Teacher vacancies (DfE)",      uses:  6, lastUsed: "2026-04-03" },
  { id: "TPL-04", name: "SEND provision (LA/DfE)",      uses: 11, lastUsed: "2026-05-12" },
  { id: "TPL-05", name: "Capital funding (DfE)",        uses:  3, lastUsed: "2026-03-22" }
];

Object.assign(window, { REGIONS, MATS, REQUESTS, STATUS_META, INBOX, AUDIT, TEMPLATES });
