export type PurchaseDocumentStatus = "pending" | "processed" | "needs_review" | "failed";
export type PurchaseLineStatus = "detected" | "confirmed" | "ignored" | "converted_to_product";

export interface PurchaseDocumentLine {
  id: number;
  document_id: number;
  user_id: number;
  line_number: number;
  raw_text: string;
  name_raw: string;
  brand_raw: string;
  model_raw: string;
  serial_number: string;
  imei: string;
  sku: string;
  category: string;
  quantity: number;
  unit_price: string | null;
  total_price: string | null;
  canonical_brand_id: number | null;
  canonical_product_id: number | null;
  linked_product_id: number | null;
  line_status: PurchaseLineStatus;
  confidence: string;
  metadata: Record<string, unknown>;
  created_at: string;
  updated_at: string;
}

export interface PurchaseDocument {
  id: number;
  user_id: number;
  canonical_store_id: number | null;
  group_id: number | null;
  vendor_raw: string;
  vendor_canonical: string;
  document_number: string;
  purchase_date: string | null;
  total_amount: string | null;
  currency: string;
  file_url: string;
  file_name: string;
  mime_type: string;
  ocr_text: string;
  extraction_status: PurchaseDocumentStatus;
  extraction_confidence: string;
  document_fingerprint?: string;
  metadata: Record<string, unknown>;
  created_at: string;
  updated_at: string;
  line_count?: number;
  confirmed_line_count?: number;
  duplicate_count?: number;
  purchase_summary?: string;
  group_name?: string;
  group_slug?: string;
}

export interface PurchaseDocumentDetail extends PurchaseDocument {
  lines: PurchaseDocumentLine[];
}

export interface PurchaseDocumentGroup {
  id: number;
  user_id: number;
  name: string;
  slug: string;
  notes: string;
  created_at: string;
  updated_at: string;
  document_count: number;
  total_amount: string | null;
}

export interface PurchaseProductCandidate {
  document_id: number;
  document_number: string;
  vendor_raw: string;
  vendor_canonical: string;
  purchase_date: string | null;
  total_amount: string | null;
  currency: string;
  file_url: string;
  file_name: string;
  mime_type: string;
  line_id: number;
  line_number: number;
  raw_text: string;
  name_raw: string;
  brand_raw: string;
  model_raw: string;
  serial_number: string;
  imei: string;
  sku: string;
  category: string;
  quantity: number;
  unit_price: string | null;
  total_price: string | null;
  linked_product_id: number | null;
  line_status: PurchaseLineStatus;
  confidence: string;
}
