/**
 * DEMO-ONLY data for the pilot car replica (Phase 1, 2026-09-12).
 *
 * Nash: "we can create the replica, per se, on how this is gonna work" —
 * nothing here is stored; the pilot dispatch and pilot driver dashboards
 * render from these objects until the backend phase (Modules C–J in
 * PILOT-MANAGEMENT-TASKS-2026-09-12.md) replaces them with real rows.
 *
 * Shapes mirror the article's §55 data objects so the swap is mechanical.
 */

import type {
  AccessScopeType,
  AssignmentStatus,
  CapabilityStatus,
  PilotCapability,
  PilotDocumentStatus,
  PilotPosition,
  ReadinessStatus,
  RelationshipStatus,
  VehiclePhotoSide,
} from '@/lib/domain/pilot'

export interface DemoPilotDocument {
  key: string
  status: PilotDocumentStatus
  expirationDate?: string
  uploadedAt?: string
}

export interface DemoPilotVehicle {
  id: string
  unitNumber: string
  year: string
  make: string
  model: string
  color: string
  plate: string
  plateState: string
  vin?: string
  equipmentType: string
  ownerType: 'pilot_driver' | 'pilot_company'
  ownerLabel: string
  assignedDriverId: string | null
  status: 'active' | 'inactive'
  notes?: string
  /** Which of the four required sides have a photo (§33). */
  photos: VehiclePhotoSide[]
}

export interface DemoPilotDriver {
  id: string
  name: string
  email: string
  phone: string
  homeBase: string
  yearsExperience: number
  statesServed: string[]
  serviceRadius: string
  capabilities: Partial<Record<PilotCapability, CapabilityStatus>>
  documents: DemoPilotDocument[]
  readiness: ReadinessStatus
  relationship: RelationshipStatus
  /** Who opened the relationship (§26 / §27). */
  requestedBy: 'company' | 'driver'
  linkedCompanies: string[]
  vehicleIds: string[]
}

export interface DemoAccessScope {
  type: AccessScopeType
  /** State code for `state`, permit label for `permit`, unused for `full_trip`. */
  value?: string
}

export interface DemoSharedPermit {
  id: string
  state: string
  permitNumber: string
  effective: string
  expires: string
  escort: string
  curfew: string
  /** Whether this permit falls inside the pilot's scope — used by the preview. */
  shared: boolean
  route?: 'ready' | 'requested' | null
  /** Permitted dimensions (inches / lbs), shown as the W · H · L · GVW row like the broker permit card. */
  dims?: { w: number; h: number; l: number; gvw: number }
}

export interface DemoUnitInfo {
  unitNumber: string
  year: string
  make: string
  model: string
  vin: string
  plate: string
  plateState: string
}

export interface DemoPilotAssignment {
  id: string
  ref: string
  carrier: string
  carrierDispatcher: { name: string; phone: string; email: string }
  carrierDriver: { name: string; phone: string; email: string }
  origin: string
  destination: string
  commodity: string
  overall: string
  weight: string
  /** Overall (truck + trailer) dimensions in inches / lbs, when known — cross-checked against each permit. */
  overallDims?: { w: number; h: number; l: number; gvw: number }
  truck: string
  trailer: string
  /**
   * Nash, 2026-09-12: "we need the truck make, model, year, VIN number, plate
   * number, state of the registration… he needs the VIN and the plate number.
   * It's important for him for legal purposes."
   */
  truckInfo: DemoUnitInfo | null
  trailerInfo: DemoUnitInfo | null
  scopes: DemoAccessScope[]
  permits: DemoSharedPermit[]
  pilotDriverId: string | null
  vehicleId: string | null
  position: PilotPosition
  status: AssignmentStatus
  /**
   * Who invited the pilot to this trip. Nash, 2026-09-12: the invoice's
   * default recipient "should equal the email of the person that invited the
   * pilot to this trip" — carrier dispatch, carrier driver, or broker.
   */
  invitedBy: 'carrier' | 'carrier_driver' | 'broker'
  /** Broker contact when a broker is on the trip. */
  broker?: { name: string; email: string }
  createdAt: string
  completedAt?: string
  /** Article §30 — "Require carrier approval when pilot company assigns a driver". */
  carrierApprovalRequired: boolean
  driverApprovedByCarrier: boolean
}

export interface DemoRelationshipLogEntry {
  at: string
  text: string
}

export interface DemoActivityEntry {
  at: string
  action: string
  detail: string
}

export interface DemoPilotCompany {
  name: string
  address: string
  phone: string
  email: string
  mainContact: string
  createdAt: string
  serviceStates: string[]
  capabilities: Partial<Record<PilotCapability, CapabilityStatus>>
  documents: DemoPilotDocument[]
  verificationStatus: string
  notes: string
}

/* ------------------------------------------------------------------ */

export const DEMO_TODAY = '2026-09-12'

export const DEMO_PILOT_COMPANY: DemoPilotCompany = {
  name: 'ABC Pilot Cars',
  address: '4120 Industrial Pkwy, Columbus, OH 43228',
  phone: '(614) 555-0142',
  email: 'dispatch@abcpilotcars.com',
  mainContact: 'Maria Lopez (dispatcher)',
  createdAt: '2026-09-04',
  serviceStates: ['OH', 'IN', 'KY', 'PA', 'WV'],
  capabilities: {
    'Lead pilot': 'Verified by admin',
    'Chase / rear pilot': 'Verified by admin',
    'High pole': 'Document uploaded',
    'Route survey': 'Self-declared',
    'Oversize escort': 'Verified by admin',
    'Superload escort': 'Self-declared',
  },
  documents: [
    { key: 'insurance', status: 'Approved', expirationDate: '2027-03-01', uploadedAt: '2026-09-04' },
    { key: 'w9', status: 'Uploaded', uploadedAt: '2026-09-04' },
    // Inside the 30-day window (§11) — created 09-04, today 09-12 → due in 22 days.
    { key: 'business_license', status: 'Not Uploaded' },
    { key: 'good_standing', status: 'Not Uploaded' },
    { key: 'company_documents', status: 'Not Uploaded' },
    { key: 'state_company_certification', status: 'Not Uploaded' },
  ],
  verificationStatus: 'Verification Incomplete — business license pending',
  notes: 'Two lead units, one high-pole unit. Night moves on request.',
}

export const DEMO_PILOT_VEHICLES: DemoPilotVehicle[] = [
  {
    id: 'veh-1',
    unitNumber: 'PC-01',
    year: '2022',
    make: 'Ford',
    model: 'F-150',
    color: 'White',
    plate: 'HLD 4471',
    plateState: 'OH',
    vin: '1FTFW1E50NFA12345',
    equipmentType: 'Lead / chase — amber bar, signs, flags',
    ownerType: 'pilot_company',
    ownerLabel: 'ABC Pilot Cars',
    assignedDriverId: 'drv-1',
    status: 'active',
    photos: ['Front', 'Back', 'Left side', 'Right side'],
  },
  {
    id: 'veh-2',
    unitNumber: 'PC-02',
    year: '2019',
    make: 'Chevrolet',
    model: 'Silverado 1500',
    color: 'Silver',
    plate: 'PLT 9082',
    plateState: 'OH',
    equipmentType: 'High pole — 18 ft pole, amber bar',
    ownerType: 'pilot_company',
    ownerLabel: 'ABC Pilot Cars',
    assignedDriverId: 'drv-2',
    status: 'active',
    photos: ['Front', 'Back', 'Left side'],
    notes: 'Right-side photo still missing.',
  },
  {
    id: 'veh-3',
    unitNumber: 'JR-1',
    year: '2021',
    make: 'Ram',
    model: '1500',
    color: 'Black',
    plate: 'ESC 2210',
    plateState: 'KY',
    equipmentType: 'Lead / chase',
    ownerType: 'pilot_driver',
    ownerLabel: 'John Ramirez (own vehicle)',
    assignedDriverId: 'drv-3',
    status: 'active',
    photos: ['Front', 'Back', 'Left side', 'Right side'],
  },
  {
    id: 'veh-4',
    unitNumber: 'PC-03',
    year: '2016',
    make: 'Toyota',
    model: 'Tundra',
    color: 'Red',
    plate: 'OLD 1188',
    plateState: 'OH',
    equipmentType: 'Chase',
    ownerType: 'pilot_company',
    ownerLabel: 'ABC Pilot Cars',
    assignedDriverId: null,
    status: 'inactive',
    photos: ['Front'],
    notes: 'Retired unit — kept for history.',
  },
]

export const DEMO_PILOT_DRIVERS: DemoPilotDriver[] = [
  {
    id: 'drv-1',
    name: 'Dana Whitfield',
    email: 'dana.whitfield@example.com',
    phone: '(614) 555-0198',
    homeBase: 'Columbus, OH',
    yearsExperience: 9,
    statesServed: ['OH', 'IN', 'KY', 'PA'],
    serviceRadius: '400 mi',
    capabilities: {
      'Lead pilot': 'Verified by admin',
      'Chase / rear pilot': 'Verified by admin',
      'Oversize escort': 'Verified by admin',
      'Route survey': 'Self-declared',
    },
    documents: [
      { key: 'w9', status: 'Uploaded', uploadedAt: '2026-09-05' },
      { key: 'driver_license', status: 'Approved', expirationDate: '2029-01-14' },
      { key: 'insurance', status: 'Approved', expirationDate: '2027-02-01' },
      { key: 'pilot_certification', status: 'Approved', expirationDate: '2027-08-30' },
      { key: 'utah_certification', status: 'Uploaded', expirationDate: '2027-05-10' },
    ],
    readiness: 'Verified Pilot',
    relationship: 'Approved',
    requestedBy: 'company',
    linkedCompanies: ['ABC Pilot Cars'],
    vehicleIds: ['veh-1'],
  },
  {
    id: 'drv-2',
    name: 'Marcus Bell',
    email: 'marcus.bell@example.com',
    phone: '(740) 555-0167',
    homeBase: 'Zanesville, OH',
    yearsExperience: 4,
    statesServed: ['OH', 'WV', 'PA'],
    serviceRadius: '250 mi',
    capabilities: {
      'High pole': 'Document uploaded',
      'Chase / rear pilot': 'Self-declared',
      'Night movement support, if applicable': 'Self-declared',
    },
    documents: [
      { key: 'w9', status: 'Uploaded', uploadedAt: '2026-09-06' },
      { key: 'driver_license', status: 'Uploaded', expirationDate: '2028-06-02' },
      { key: 'insurance', status: 'Expiring Soon', expirationDate: '2026-09-25' },
      { key: 'pilot_certification', status: 'Pending Review', expirationDate: '2027-01-15' },
    ],
    readiness: 'Ready for Assignment',
    relationship: 'Approved',
    requestedBy: 'driver',
    linkedCompanies: ['ABC Pilot Cars', 'Elite Escort Services'],
    vehicleIds: ['veh-2'],
  },
  {
    id: 'drv-3',
    name: 'John Ramirez',
    email: 'john.ramirez@example.com',
    phone: '(859) 555-0121',
    homeBase: 'Lexington, KY',
    yearsExperience: 12,
    statesServed: ['KY', 'OH', 'TN', 'IN'],
    serviceRadius: '500 mi',
    capabilities: {
      'Lead pilot': 'Self-declared',
      'Chase / rear pilot': 'Self-declared',
      'Superload escort': 'Self-declared',
    },
    documents: [
      { key: 'w9', status: 'Uploaded', uploadedAt: '2026-09-10' },
      { key: 'driver_license', status: 'Uploaded', expirationDate: '2027-11-20' },
      { key: 'insurance', status: 'Uploaded', expirationDate: '2027-04-18' },
      { key: 'pilot_certification', status: 'Not Uploaded' },
    ],
    readiness: 'Documents Missing',
    // §27 — the driver said he works with us and asked to connect.
    relationship: 'Pending',
    requestedBy: 'driver',
    linkedCompanies: ['Independent direct work'],
    vehicleIds: ['veh-3'],
  },
  {
    id: 'drv-4',
    name: 'Priya Natarajan',
    email: 'priya.n@example.com',
    phone: '(317) 555-0139',
    homeBase: 'Indianapolis, IN',
    yearsExperience: 6,
    statesServed: ['IN', 'IL', 'OH'],
    serviceRadius: '300 mi',
    capabilities: { 'Lead pilot': 'Self-declared' },
    documents: [
      { key: 'w9', status: 'Not Uploaded' },
      { key: 'driver_license', status: 'Not Uploaded' },
      { key: 'insurance', status: 'Not Uploaded' },
      { key: 'pilot_certification', status: 'Not Uploaded' },
    ],
    readiness: 'Email Not Verified',
    // §26 — we asked her; she has not answered yet.
    relationship: 'Pending',
    requestedBy: 'company',
    linkedCompanies: [],
    vehicleIds: [],
  },
  {
    id: 'drv-5',
    name: 'Tom Sadler',
    email: 'tom.sadler@example.com',
    phone: '(304) 555-0111',
    homeBase: 'Wheeling, WV',
    yearsExperience: 15,
    statesServed: ['WV', 'PA', 'OH'],
    serviceRadius: '350 mi',
    capabilities: { 'Lead pilot': 'Expired', 'Chase / rear pilot': 'Expired' },
    documents: [
      { key: 'w9', status: 'Uploaded', uploadedAt: '2026-08-01' },
      { key: 'driver_license', status: 'Approved', expirationDate: '2028-03-03' },
      { key: 'insurance', status: 'Expired', expirationDate: '2026-08-31' },
      { key: 'pilot_certification', status: 'Expired', expirationDate: '2026-07-15' },
    ],
    readiness: 'Expired Documents',
    relationship: 'Suspended',
    requestedBy: 'company',
    linkedCompanies: ['ABC Pilot Cars'],
    vehicleIds: [],
  },
]

// Nash, 2026-09-13: the real trip HH-95595781 (Brawley, CA → Terlingua, TX,
// ATLAS LOGISTICS GROUP INC) appears on the broker and carrier dashboards;
// this mirrors it on the pilot dispatch dashboard with John Cena hired for
// New Mexico by the carrier dispatcher.
DEMO_PILOT_DRIVERS.push({
  id: 'drv-6',
  name: 'John Cena',
  email: 'john.cena@pilotcars.example',
  phone: '(505) 555-0147',
  homeBase: 'Las Cruces, NM',
  yearsExperience: 7,
  statesServed: ['NM', 'AZ', 'TX'],
  serviceRadius: '450 mi',
  capabilities: { 'Lead pilot': 'Verified by admin', 'Chase / rear pilot': 'Verified by admin', 'High pole': 'Document uploaded' },
  documents: [
    { key: 'w9', status: 'Uploaded', uploadedAt: '2026-09-08' },
    { key: 'driver_license', status: 'Approved', expirationDate: '2028-09-01' },
    { key: 'insurance', status: 'Approved', expirationDate: '2027-06-30' },
    { key: 'pilot_certification', status: 'Approved', expirationDate: '2027-09-15' },
  ],
  readiness: 'Verified Pilot',
  relationship: 'Approved',
  requestedBy: 'company',
  linkedCompanies: ['ABC Pilot Cars'],
  vehicleIds: ['veh-5'],
})
DEMO_PILOT_VEHICLES.push({
  id: 'veh-5',
  unitNumber: 'JC-1',
  year: '2023',
  make: 'GMC',
  model: 'Sierra 1500',
  color: 'White',
  plate: 'PLT 4471',
  plateState: 'NM',
  equipmentType: 'Lead / chase — amber bar, signs, flags, 18 ft high pole',
  ownerType: 'pilot_company',
  ownerLabel: 'ABC Pilot Cars',
  assignedDriverId: 'drv-6',
  status: 'active',
  photos: ['Front', 'Back', 'Left side', 'Right side'],
})

export const DEMO_RELATIONSHIP_LOG: DemoRelationshipLogEntry[] = [
  { at: '2026-09-11 16:40', text: 'John Ramirez requested to connect with ABC Pilot Cars (driver-initiated).' },
  { at: '2026-09-10 09:15', text: 'Maria Lopez sent a relationship request to Priya Natarajan.' },
  { at: '2026-09-09 14:02', text: 'Maria Lopez suspended Tom Sadler — reason: insurance expired 2026-08-31.' },
  { at: '2026-09-06 11:20', text: 'Maria Lopez approved Marcus Bell (driver-initiated request).' },
  { at: '2026-09-05 08:45', text: 'Dana Whitfield approved the request from ABC Pilot Cars.' },
]

export const DEMO_PILOT_ASSIGNMENTS: DemoPilotAssignment[] = [
  {
    id: 'asg-1',
    ref: 'HH-2041',
    carrier: 'Ridgeline Heavy Haul',
    carrierDispatcher: { name: 'Kevin Ortiz', phone: '(330) 555-0177', email: 'dispatch@ridgelinehh.com' },
    carrierDriver: { name: 'Luis Fernandez', phone: '(330) 555-0188', email: 'luis.f@ridgelinehh.com' },
    origin: 'Toledo, OH',
    destination: 'Pittsburgh, PA',
    commodity: 'Transformer, 2 pc',
    overall: "14'2\" W × 15'6\" H × 118' L",
    weight: '186,000 lbs',
    overallDims: { w: 170, h: 186, l: 1416, gvw: 186000 },
    truck: 'Peterbilt 389 · Unit 412',
    trailer: '13-axle Goldhofer',
    truckInfo: { unitNumber: '412', year: '2021', make: 'Peterbilt', model: '389', vin: '1XPBD49X1MD756021', plate: 'PJK 4471', plateState: 'OH' },
    trailerInfo: { unitNumber: 'T-19', year: '2018', make: 'Goldhofer', model: 'THP/SL 13-axle', vin: 'W09THPSL5JG018844', plate: 'TRL 99835', plateState: 'WA' },
    // §17 — Ohio state access: every OH permit, including ones uploaded later.
    scopes: [{ type: 'state', value: 'OH' }],
    permits: [
      { id: 'p-1', state: 'OH', permitNumber: 'OH-SL-88214', effective: '2026-09-12', expires: '2026-09-16', escort: '2 escorts (lead + chase), high pole over 14\'6"', curfew: 'No movement 7–9 AM / 4–6 PM in Franklin County', shared: true, route: 'ready', dims: { w: 170, h: 180, l: 1416, gvw: 186000 } },
      { id: 'p-2', state: 'OH', permitNumber: 'OH-SL-88301 (uploaded 09-11)', effective: '2026-09-13', expires: '2026-09-17', escort: 'Same escort set', curfew: 'Sunrise to sunset only', shared: true, route: null, dims: { w: 170, h: 186, l: 1416, gvw: 186000 } },
      { id: 'p-3', state: 'PA', permitNumber: 'PA-OS-55120', effective: '2026-09-14', expires: '2026-09-18', escort: '3 escorts incl. high pole', curfew: 'No movement Fri 3 PM – Mon 9 AM', shared: false, route: null, dims: { w: 170, h: 186, l: 1416, gvw: 186000 } },
    ],
    pilotDriverId: 'drv-1',
    vehicleId: 'veh-1',
    position: 'Lead',
    status: 'in progress',
    invitedBy: 'carrier',
    createdAt: '2026-09-09',
    carrierApprovalRequired: true,
    driverApprovedByCarrier: true,
  },
  {
    id: 'asg-2',
    ref: 'HH-2050',
    carrier: 'Ridgeline Heavy Haul',
    carrierDispatcher: { name: 'Kevin Ortiz', phone: '(330) 555-0177', email: 'dispatch@ridgelinehh.com' },
    carrierDriver: { name: 'Anita Shaw', phone: '(330) 555-0190', email: 'anita.s@ridgelinehh.com' },
    origin: 'Cincinnati, OH',
    destination: 'Charleston, WV',
    commodity: 'Excavator CAT 390',
    overall: "12'6\" W × 14'8\" H × 92' L",
    weight: '142,500 lbs',
    truck: 'Kenworth T880 · Unit 207',
    trailer: '9-axle lowboy',
    truckInfo: { unitNumber: '207', year: '2019', make: 'Kenworth', model: 'T880', vin: '1XKZD49X6KJ214870', plate: 'RHH 2070', plateState: 'OH' },
    trailerInfo: { unitNumber: 'T-07', year: '2016', make: 'Trail King', model: 'TK110HDG 9-axle', vin: '1TKJ05339GB051207', plate: 'TRL 51207', plateState: 'OH' },
    // §18 — one permit only; a later WV permit is NOT shared automatically.
    scopes: [{ type: 'permit', value: 'WV-OS-30117' }],
    permits: [
      { id: 'p-4', state: 'OH', permitNumber: 'OH-OS-90410', effective: '2026-09-15', expires: '2026-09-19', escort: '1 chase', curfew: 'None', shared: false, route: null },
      { id: 'p-5', state: 'WV', permitNumber: 'WV-OS-30117', effective: '2026-09-16', expires: '2026-09-20', escort: 'Lead + chase, high pole', curfew: 'Daylight only; no holiday movement', shared: true, route: 'requested' },
      { id: 'p-6', state: 'WV', permitNumber: 'WV-OS-30122 (uploaded 09-12)', effective: '2026-09-17', expires: '2026-09-21', escort: 'Lead + chase', curfew: 'Daylight only', shared: false, route: null },
    ],
    pilotDriverId: 'drv-2',
    vehicleId: 'veh-2',
    position: 'High pole',
    status: 'accepted',
    // The carrier DRIVER added this pilot — her email is the invoice default.
    invitedBy: 'carrier_driver',
    createdAt: '2026-09-11',
    carrierApprovalRequired: true,
    driverApprovedByCarrier: false,
  },
  {
    id: 'asg-3',
    ref: 'HH-2057',
    carrier: 'Summit Freight Brokerage (broker) · carrier TBD',
    carrierDispatcher: { name: 'Pending carrier assignment', phone: '—', email: '—' },
    carrierDriver: { name: 'Pending', phone: '—', email: '—' },
    origin: 'Louisville, KY',
    destination: 'Columbus, OH',
    commodity: 'Precast beams',
    overall: "10' W × 14' H × 130' L",
    weight: '124,000 lbs',
    truck: '—',
    trailer: '—',
    truckInfo: null,
    trailerInfo: null,
    // §19 — full trip: operational data, rate confirmation still hidden.
    scopes: [{ type: 'full_trip' }],
    permits: [
      { id: 'p-7', state: 'KY', permitNumber: 'KY-OS-71002', effective: '2026-09-18', expires: '2026-09-22', escort: 'Lead + chase', curfew: 'No rush-hour movement in Jefferson County', shared: true, route: null },
      { id: 'p-8', state: 'OH', permitNumber: 'OH-OS-90502', effective: '2026-09-19', expires: '2026-09-23', escort: 'Lead + chase', curfew: 'Sunrise to sunset', shared: true, route: null },
    ],
    pilotDriverId: null,
    vehicleId: null,
    position: 'Lead',
    status: 'invited',
    invitedBy: 'broker',
    broker: { name: 'Erin Blake', email: 'erin@summitfreight.com' },
    createdAt: '2026-09-12',
    carrierApprovalRequired: false,
    driverApprovedByCarrier: false,
  },
  {
    id: 'asg-4',
    ref: 'HH-1988',
    carrier: 'Blue Ridge Transport',
    carrierDispatcher: { name: 'Sam Kowalski', phone: '(412) 555-0150', email: 'ops@blueridgetransport.com' },
    carrierDriver: { name: 'Derek Hall', phone: '(412) 555-0151', email: 'derek.h@blueridgetransport.com' },
    origin: 'Dayton, OH',
    destination: 'Indianapolis, IN',
    commodity: 'Wind blade',
    overall: "11' W × 14'6\" H × 205' L",
    weight: '98,000 lbs',
    truck: 'Volvo VNL · Unit 88',
    trailer: 'Blade trailer',
    truckInfo: { unitNumber: '88', year: '2020', make: 'Volvo', model: 'VNL 860', vin: '4V4NC9EH1LN238811', plate: 'BRT 0088', plateState: 'PA' },
    trailerInfo: { unitNumber: 'B-2', year: '2017', make: 'Schnabel', model: 'Blade 205', vin: '5SZBL4726HA000902', plate: 'TRL 00902', plateState: 'PA' },
    scopes: [{ type: 'state', value: 'OH' }, { type: 'state', value: 'IN' }],
    permits: [
      { id: 'p-9', state: 'OH', permitNumber: 'OH-SL-86001', effective: '2026-08-28', expires: '2026-09-01', escort: '2 escorts', curfew: 'None', shared: true, route: 'ready' },
      { id: 'p-10', state: 'IN', permitNumber: 'IN-OS-44190', effective: '2026-08-29', expires: '2026-09-02', escort: '2 escorts', curfew: 'None', shared: true, route: 'ready' },
    ],
    pilotDriverId: 'drv-1',
    vehicleId: 'veh-1',
    position: 'Chase',
    status: 'completed',
    invitedBy: 'carrier',
    createdAt: '2026-08-26',
    completedAt: '2026-09-02',
    carrierApprovalRequired: false,
    driverApprovedByCarrier: true,
  },
]

// Nash, 2026-09-12: "if nothing was shared, he's not gonna see any permit."
// The carrier chose "decide later" on the invitation.
DEMO_PILOT_ASSIGNMENTS.push({
  id: 'asg-5',
  ref: 'HH-2061',
  carrier: 'Ridgeline Heavy Haul',
  carrierDispatcher: { name: 'Kevin Ortiz', phone: '(330) 555-0177', email: 'dispatch@ridgelinehh.com' },
  carrierDriver: { name: 'Luis Fernandez', phone: '(330) 555-0188', email: 'luis.f@ridgelinehh.com' },
  origin: 'Akron, OH',
  destination: 'Erie, PA',
  commodity: 'Boiler section',
  overall: "13' W × 15' H × 96' L",
  weight: '150,000 lbs',
  truck: 'Peterbilt 389 · Unit 412',
  trailer: '13-axle Goldhofer',
  truckInfo: { unitNumber: '412', year: '2021', make: 'Peterbilt', model: '389', vin: '1XPBD49X1MD756021', plate: 'PJK 4471', plateState: 'OH' },
  trailerInfo: { unitNumber: 'T-19', year: '2018', make: 'Goldhofer', model: 'THP/SL 13-axle', vin: 'W09THPSL5JG018844', plate: 'TRL 99835', plateState: 'WA' },
  scopes: [],
  permits: [
    { id: 'p-11', state: 'OH', permitNumber: 'OH-SL-88410', effective: '2026-09-20', expires: '2026-09-24', escort: '2 escorts', curfew: 'Sunrise to sunset', shared: false, route: null },
    { id: 'p-12', state: 'PA', permitNumber: 'PA-OS-55201', effective: '2026-09-21', expires: '2026-09-25', escort: '3 escorts incl. high pole', curfew: 'No weekend movement', shared: false, route: null },
  ],
  pilotDriverId: null,
  vehicleId: null,
  position: 'Lead',
  status: 'invited',
  invitedBy: 'carrier',
  createdAt: '2026-09-12',
  carrierApprovalRequired: true,
  driverApprovedByCarrier: false,
})

DEMO_PILOT_ASSIGNMENTS.unshift({
  id: 'asg-6',
  ref: 'HH-95595781',
  carrier: 'ATLAS LOGISTICS GROUP INC',
  carrierDispatcher: { name: 'Vlad Croitoru', phone: '+1 253-777-0272', email: 'test_dispatcher@users.local' },
  carrierDriver: { name: 'Dexter Higginbottom', phone: '—', email: 'test_driver@users.local' },
  origin: 'Brawley, CA',
  destination: 'Terlingua, TX',
  commodity: 'Caterpillar 14M3 — motor grader',
  overall: "11' W × 14' H × 80' L",
  weight: '113,000 lbs',
  overallDims: { w: 132, h: 168, l: 960, gvw: 113000 },
  truck: 'Unit 395',
  trailer: 'Lowboy',
  truckInfo: { unitNumber: '395', year: '2022', make: 'Peterbilt', model: '389', vin: '1XPBD49X4ND765395', plate: 'C99 8351', plateState: 'WA' },
  trailerInfo: { unitNumber: 'T-395', year: '2019', make: 'Trail King', model: 'TK110HDG lowboy', vin: '1TKJ05339KB051395', plate: '2847 TR', plateState: 'ME' },
  // New Mexico only — hired by the carrier dispatcher (state access).
  scopes: [{ type: 'state', value: 'NM' }],
  permits: [
    { id: 'p-13', state: 'CA', permitNumber: '95595781-CA', effective: '2026-09-12', expires: '2026-09-19', escort: '1 chase', curfew: 'No movement in LA metro 6–9 AM / 3–7 PM', shared: false, route: null },
    { id: 'p-14', state: 'AZ', permitNumber: '95595781-AZ', effective: '2026-09-13', expires: '2026-09-20', escort: '1 chase', curfew: 'Daylight only', shared: false, route: null },
    { id: 'p-15', state: 'NM', permitNumber: '95595781-NM', effective: '2026-09-14', expires: '2026-09-21', escort: 'Lead + chase, high pole over 14\'6"', curfew: 'Daylight only; no Sunday movement', shared: true, route: 'ready', dims: { w: 132, h: 168, l: 960, gvw: 113000 } },
    { id: 'p-16', state: 'TX', permitNumber: '95595781-TX', effective: '2026-09-15', expires: '2026-09-22', escort: '2 escorts', curfew: 'No movement Fri PM – Mon AM in Austin/San Antonio', shared: false, route: null },
  ],
  pilotDriverId: 'drv-6',
  vehicleId: 'veh-5',
  position: 'Lead',
  status: 'in progress',
  invitedBy: 'carrier',
  createdAt: '2026-09-12',
  carrierApprovalRequired: true,
  driverApprovedByCarrier: true,
})

/** Article §58 — the activity log, newest first. */
export const DEMO_PILOT_ACTIVITY: DemoActivityEntry[] = [
  { at: '2026-09-12 10:05', action: 'Pilot company invited', detail: 'Summit Freight Brokerage invited ABC Pilot Cars to HH-2057 (full trip access).' },
  { at: '2026-09-12 09:40', action: 'Permit access granted', detail: 'Ridgeline Heavy Haul shared WV-OS-30117 on HH-2050 with ABC Pilot Cars.' },
  { at: '2026-09-11 17:10', action: 'State access granted', detail: 'A new Ohio permit (OH-SL-88301) became visible on HH-2041 through Ohio state access.' },
  { at: '2026-09-11 15:30', action: 'Pilot company assigned driver', detail: 'Maria Lopez assigned Marcus Bell (unit PC-02) to HH-2050 — waiting for carrier approval.' },
  { at: '2026-09-10 08:20', action: 'Pilot ordered route', detail: 'Dana Whitfield ordered an Express Route for OH-SL-88214 on HH-2041.' },
  { at: '2026-09-09 13:00', action: 'Pilot driver assigned vehicle', detail: 'Unit PC-01 linked to Dana Whitfield for HH-2041.' },
  { at: '2026-09-09 12:45', action: 'Invite accepted', detail: 'ABC Pilot Cars accepted the HH-2041 assignment (Ohio state access).' },
  { at: '2026-09-06 11:20', action: 'Documents uploaded', detail: 'Marcus Bell uploaded W-9, driver license, insurance, pilot certification.' },
  { at: '2026-09-04 16:00', action: 'Email validated', detail: 'dispatch@abcpilotcars.com validated.' },
  { at: '2026-09-02 18:30', action: 'Pilot assignment completed', detail: 'HH-1988 marked completed by Dana Whitfield.' },
]

/** Carriers and brokers the company works with (Contacts tab). */
export const DEMO_PILOT_CONTACTS = [
  { name: 'Kevin Ortiz', company: 'Ridgeline Heavy Haul', role: 'Carrier dispatcher', phone: '(330) 555-0177', email: 'dispatch@ridgelinehh.com' },
  { name: 'Sam Kowalski', company: 'Blue Ridge Transport', role: 'Carrier dispatcher', phone: '(412) 555-0150', email: 'ops@blueridgetransport.com' },
  { name: 'Erin Blake', company: 'Summit Freight Brokerage', role: 'Broker', phone: '(502) 555-0133', email: 'erin@summitfreight.com' },
]

/** The pilot driver preview signs in as Dana Whitfield. */
export const DEMO_PILOT_DRIVER_ME_ID = 'drv-1'

export function demoDriver(id: string | null | undefined): DemoPilotDriver | undefined {
  return DEMO_PILOT_DRIVERS.find((d) => d.id === id)
}

export function demoVehicle(id: string | null | undefined): DemoPilotVehicle | undefined {
  return DEMO_PILOT_VEHICLES.find((v) => v.id === id)
}

/** The person who invited the pilot — name + email (Nash, 2026-09-12). */
export function inviterOf(a: DemoPilotAssignment): { name: string; email: string; role: string } {
  if (a.invitedBy === 'broker' && a.broker) return { ...a.broker, role: 'Broker' }
  if (a.invitedBy === 'carrier_driver') return { name: a.carrierDriver.name, email: a.carrierDriver.email, role: 'Carrier driver' }
  return { name: a.carrierDispatcher.name, email: a.carrierDispatcher.email, role: 'Carrier dispatcher' }
}

/** Trip contacts offered in the recipient dropdown (Nash: "show me the email of the dispatch, email of the driver"). */
export function tripContactsOf(a: DemoPilotAssignment): { name: string; email: string; role: string }[] {
  const list = [
    { name: a.carrierDispatcher.name, email: a.carrierDispatcher.email, role: 'Carrier dispatcher' },
    { name: a.carrierDriver.name, email: a.carrierDriver.email, role: 'Carrier driver' },
  ].filter((c) => c.email && c.email !== '—')
  if (a.broker) list.push({ ...a.broker, role: 'Broker' })
  return list
}

export function scopeSummary(scopes: DemoAccessScope[]): string {
  if (scopes.length === 0) return 'Nothing shared yet — carrier will decide'
  return scopes
    .map((s) =>
      s.type === 'full_trip'
        ? 'Full trip'
        : s.type === 'state'
          ? `${s.value} (state)`
          : `${s.value} (permit)`,
    )
    .join(' · ')
}

/** Article §44 — a scoped Agent conversation showing the refusal on a hidden document. */
export const DEMO_PILOT_AGENT_CHAT = [
  { who: 'you' as const, text: 'Do I need a high pole for the Ohio permit?' },
  { who: 'agent' as const, text: 'Yes. OH-SL-88214 requires two escorts (lead and chase) and a high pole because the load is 15\'6" — over the 14\'6" threshold on the permit.' },
  { who: 'you' as const, text: 'What is the curfew in Franklin County?' },
  { who: 'agent' as const, text: 'No movement 7–9 AM and 4–6 PM in Franklin County. Outside those windows the permit allows daylight travel.' },
  { who: 'you' as const, text: 'Can you show me the rate confirmation for this load?' },
  { who: 'agent' as const, text: 'That document is not available for your role. Pilot access covers permits, routes, escort and curfew details for the states shared with you.' },
  { who: 'you' as const, text: 'What are the Pennsylvania restrictions?' },
  { who: 'agent' as const, text: 'Pennsylvania has not been shared with you on this trip. Your access covers Ohio permits only — ask the carrier dispatcher if you need PA.' },
]
