// tdd-guard:skip — pure type declarations, no runtime logic to test.
// Behaviour that consumes these types is tested in time-engine / templates / export specs.

import type { Locale } from '@/lib/i18n/i18n-context'

/**
 * Domain types for the project Agenda feature.
 *
 * These mirror the database schema in `supabase/migrations/supabase-migration-agenda-schema.sql`
 * (snake_case columns kept verbatim per CLAUDE.md "DB field → TypeScript mapping").
 * The nested `days` / `items` / `participants` shape is the in-memory aggregate
 * the editor and exporters operate on; it is assembled from the flat tables.
 */

/** Agenda content language. Reuses the app's 4 supported locales. */
export type AgendaLanguage = Locale // 'de' | 'en' | 'es' | 'zh'

/** Workshop type — drives which template seeds the agenda. */
export type AgendaType =
  | 'fabrikanalyse'
  | 'lsc_workshop'
  | 'kapa_workshop'
  | 'sonstiges'

/** How the agenda was initially populated. */
export type GenerationMode = 'suggest' | 'empty'

/** Day-start convention chosen in the wizard. */
export type StartMode = 'morning' | 'afternoon' | 'custom'

export type AgendaStatus = 'draft' | 'final'

/**
 * Semantic type of a single agenda row. Drives colour-coding in the editor
 * and lets the time engine treat breaks/travel specially.
 */
export type AgendaItemType =
  | 'workshop'
  | 'presentation'
  | 'shopfloor'
  | 'break'
  | 'lunch'
  | 'travel'
  | 'internal'
  | 'management'
  | 'other'

export type ParticipantType = 'host' | 'supplier' | 'external'

export type ExportType = 'pdf' | 'xlsx'

/** `HH:MM` 24-hour time string, e.g. `"08:30"`. */
export type TimeString = string

/** `YYYY-MM-DD` date string. */
export type DateString = string

export interface AgendaItem {
  id: string
  agenda_day_id: string
  sort_order: number
  /** Computed by the time engine; persisted for export/print fidelity. */
  start_time: TimeString | null
  /** Computed by the time engine. */
  end_time: TimeString | null
  duration_minutes: number
  title: string
  description: string | null
  responsible: string | null
  participant_group: string | null
  location: string | null
  item_type: AgendaItemType
  comments: string | null
  required_information: string | null
  /** When true, `start_time` is a manual anchor; the engine chains around it. */
  is_time_fixed: boolean
  /** Optional per-item colour override (hex). Null = use the item-type default. */
  color: string | null
}

export interface AgendaDay {
  id: string
  agenda_id: string
  date: DateString | null
  /** 1-based position of this day within the agenda. */
  day_index: number
  title: string | null
  is_travel_day: boolean
  start_time: TimeString | null
  end_time: TimeString | null
  sort_order: number
  items: AgendaItem[]
}

export interface AgendaParticipant {
  id: string
  agenda_id: string
  /** Links to a consultant/user when auto-imported; null for manual entries. */
  person_id: string | null
  name: string
  company: string | null
  department: string | null
  /** FK auf department_master_data; server-seitig aus department aufgelöst (KAR-704 A2). */
  department_id: string | null
  position: string | null
  role: string | null
  participant_type: ParticipantType
  email: string | null
  comment: string | null
  is_auto_imported_from_project: boolean
  sort_order: number
}

export interface AgendaExportRecord {
  id: string
  agenda_id: string
  export_type: ExportType
  file_path: string | null
  generated_by: string | null
  generated_at: string
  language: AgendaLanguage
  includes_supplier_logos: boolean
  includes_bmw_logo: boolean
}

export interface Agenda {
  id: string
  project_id: string
  title: string
  language: AgendaLanguage
  agenda_type: AgendaType
  generation_mode: GenerationMode
  start_date: DateString | null
  end_date: DateString | null
  first_day_is_travel_day: boolean
  start_mode: StartMode
  default_day_start_time: TimeString
  default_day_end_time: TimeString
  objective: string | null
  status: AgendaStatus
  created_by: string | null
  updated_by: string | null
  created_at: string
  updated_at: string
  days: AgendaDay[]
  participants: AgendaParticipant[]
}

/** Project context the agenda header + filename derive from. */
export interface AgendaProjectContext {
  projectId: string
  projectCode: string | null
  supplierName: string
  plantLocation: string | null
  /** Storage keys of up to two supplier logos, when uploaded. */
  supplierLogoKeys: string[]
}
