export type RepairIncidentStatus =
  | "open"
  | "sent"
  | "received"
  | "diagnosing"
  | "awaiting_parts"
  | "repaired"
  | "replaced"
  | "rejected"
  | "closed";

export interface ProductMedia {
  id: number;
  user_id: number;
  product_id: number;
  kind: string;
  file_url: string;
  file_name: string;
  mime_type: string;
  caption: string;
  sort_order: number;
  created_at: string;
}

export interface IncidentAttachment {
  id: number;
  user_id: number;
  incident_id: number;
  kind: string;
  file_url: string;
  file_name: string;
  mime_type: string;
  caption: string;
  sort_order: number;
  created_at: string;
}

export interface RepairIncident {
  id: number;
  user_id: number;
  product_id: number;
  purchase_document_line_id: number | null;
  incident_number: string;
  title: string;
  incident_type: string;
  status: RepairIncidentStatus;
  detected_at: string;
  delivered_at: string | null;
  delivery_place: string;
  received_by: string;
  description: string;
  symptom: string;
  accessories: string;
  sat_name: string;
  sat_reference: string;
  diagnosis: string;
  technician_notes: string;
  estimated_cost: string | null;
  resolution: string;
  replaced_with_new: boolean;
  replaced_with_refurbished: boolean;
  user_rating: number | null;
  user_rating_notes: string;
  share_public_rating: boolean;
  closed_at: string | null;
  created_at: string;
  updated_at: string;
}

export interface RepairIncidentListItem extends RepairIncident {
  product_name: string;
  product_brand: string;
  product_model: string;
  product_category: string;
  product_status: string;
  product_days_remaining: number;
  attachment_count: number;
  media_count: number;
}

export interface RepairIncidentDetail {
  incident: RepairIncident;
  product: {
    id: number;
    name: string;
    brand: string;
    model: string;
    category: string;
    status: string;
    days_remaining: number;
    effective_end_date: string;
  };
  attachments: IncidentAttachment[];
  media: ProductMedia[];
}

export interface RepairIncidentStats {
  total: number;
  open: number;
  resolved: number;
  closed: number;
  avg_rating: number | null;
  top_brands: Array<{ label: string; count: number }>;
  top_models: Array<{ label: string; count: number }>;
  top_products: Array<{ label: string; count: number }>;
}
