/**
 * DEMO-ONLY pilot cars on real trips (Nash, 2026-09-12).
 *
 * "For any trip that has the state of New Mexico… New Mexico should be marked
 * that a pilot car was hired, put a random name for the pilot car and a random
 * phone number and email, and also for the pilot dispatch… the second state…
 * will be Arizona… the pilot car could be John Cena, and the pilot dispatch
 * could be Mark Cuban."
 *
 * Same idea as the demo current state (current-state.ts): an overlay so the
 * design can be felt on the existing trips without writing fake people into
 * the database. A real pilot participant on the trip always wins; the demo
 * pair appears only where no real pilot covers the state.
 */

import type { TripParticipant } from '@/types/db'
import { paperworkList, type PilotPaperworkDoc } from '@/lib/domain/pilot'

export const DEMO_PILOT_STATES = ['NM', 'AZ'] as const

export type DemoPilotContact = TripParticipant & { kind: 'Pilot driver' | 'Pilot dispatch'; demo: true }

const PEOPLE = [
  { id: 'demo-pilot-driver', kind: 'Pilot driver' as const, name: 'John Cena', phone: '(505) 555-0147', email: 'john.cena@pilotcars.example' },
  { id: 'demo-pilot-dispatch', kind: 'Pilot dispatch' as const, name: 'Mark Cuban', phone: '(602) 555-0199', email: 'mark.cuban@pilotdispatch.example' },
]

/** Is this a state the demo pilot pair is hired for? */
export function isDemoPilotState(state: string | null | undefined): boolean {
  return !!state && (DEMO_PILOT_STATES as readonly string[]).includes(state)
}

/** Which of a trip's states carry the demo pilot pair — for dashboard badges. */
export function demoPilotStatesIn(states: string[]): string[] {
  return DEMO_PILOT_STATES.filter((s) => states.includes(s))
}

/** The demo pilot pair for a trip, shaped like trip participants. */
export function demoPilotContacts(tripId: string): DemoPilotContact[] {
  const now = '2026-09-12T09:00:00.000Z'
  return PEOPLE.map((p) => ({
    id: `${p.id}-${tripId}`,
    trip_id: tripId,
    user_id: null,
    email: p.email,
    name: p.name,
    phone: p.phone,
    phone_ext: null,
    role: 'pilot',
    status: 'active',
    invited_by: null,
    completed_at: null,
    completion_prompt_dismissed_at: null,
    share_chat: true,
    created_at: now,
    kind: p.kind,
    demo: true,
  }) as DemoPilotContact)
}

/**
 * Paperwork the demo pair shows on the carrier's "My Pilot" tab (Nash,
 * 2026-09-13). The driver is in order; the dispatch is missing its business
 * license so the missing-paperwork alert can be seen.
 */
export function demoPilotPaperwork(kind: DemoPilotContact['kind']): PilotPaperworkDoc[] {
  return kind === 'Pilot driver'
    ? paperworkList('pilot_driver', [
        { key: 'w9', status: 'Uploaded', uploadedAt: '2026-09-02' },
        { key: 'driver_license', status: 'Approved', expirationDate: '2029-04-18' },
        { key: 'insurance', status: 'Approved', expirationDate: '2027-06-30' },
        { key: 'pilot_certification', status: 'Approved', expirationDate: '2027-11-01' },
        { key: 'state_certification', status: 'Uploaded', expirationDate: '2027-02-15' },
      ])
    : paperworkList('pilot_company', [
        { key: 'insurance', status: 'Approved', expirationDate: '2027-01-31', uploadedAt: '2026-09-02' },
        { key: 'w9', status: 'Uploaded', uploadedAt: '2026-09-02' },
        { key: 'business_license', status: 'Not Uploaded' },
      ])
}

/** The access line the demo pair holds — the two states, nothing else. */
export const DEMO_PILOT_ACCESS = `States: ${DEMO_PILOT_STATES.join(', ')}`
