export type RepairStatus =
  | "new"
  | "accepted"
  | "diagnosis"
  | "estimate"
  | "waiting_for_customer"
  | "approved"
  | "repair"
  | "final_test"
  | "ready_for_pickup"
  | "shipped"
  | "completed"
  | "cancelled";

export type RepairPriority = "low" | "normal" | "high" | "urgent";
export type RepairSource = "manual" | "website" | "customer_portal" | "email" | "phone";

export interface Repair {
  id: number;
  repair_number: string;
  customer_id: number | null;
  contact_id: number | null;
  status: RepairStatus;
  priority: RepairPriority;
  source: RepairSource;
  source_reference: string | null;
  customer_name: string;
  customer_email: string;
  customer_phone: string;
  device_manufacturer: string;
  device_model: string;
  device_serial_number: string | null;
  device_type: string;
  accessories: string;
  fault_description: string;
  previous_work: string;
  device_opened: boolean;
  intake_notes: string;
  diagnosis_notes: string;
  repair_notes: string;
  estimate_notes: string;
  estimated_cost_cents: number | null;
  approved_at: string | null;
  completed_at: string | null;
  created_at: string;
  updated_at: string;
}

export interface RepairPayload {
  customer_id: number | null;
  contact_id: number | null;
  status: RepairStatus;
  priority: RepairPriority;
  source: RepairSource;
  source_reference: string | null;
  customer_name: string;
  customer_email: string | null;
  customer_phone: string;
  device_manufacturer: string;
  device_model: string;
  device_serial_number: string | null;
  device_type: string;
  accessories: string;
  fault_description: string;
  previous_work: string;
  device_opened: boolean;
  intake_notes: string;
  diagnosis_notes: string;
  repair_notes: string;
  estimate_notes: string;
  estimated_cost_cents: number | null;
}

export interface RepairListResponse {
  items: Repair[];
  total: number;
  limit: number;
  offset: number;
}

export interface RepairStatusHistory {
  id: number;
  repair_id: number;
  old_status: string | null;
  new_status: RepairStatus;
  note: string | null;
  actor_user_id: number | null;
  actor_username: string;
  actor_display_name: string;
  created_at: string;
}

export interface RepairPublicLink {
  is_active: boolean;
  token_hint: string | null;
  expires_at: string | null;
  last_used_at: string | null;
  created_at: string | null;
  revoked_at: string | null;
  public_status_path: string | null;
}

export interface RepairPublicLinkCreated extends RepairPublicLink {
  token: string;
  public_status_path: string;
}

export interface RepairNotificationTemplate {
  event_type: string;
  status: RepairStatus | null;
  subject: string;
  text: string;
  html: string | null;
}

export interface RepairNotificationEvent {
  id: number;
  repair_id: number;
  event_type: string;
  channel: string;
  recipient: string;
  subject: string;
  status: "pending" | "sent" | "failed" | "skipped";
  error_message: string | null;
  created_at: string;
  sent_at: string | null;
}

export interface RepairNotificationOverview {
  templates: RepairNotificationTemplate[];
  events: RepairNotificationEvent[];
}
