// ===== Database tables (matching real Supabase schema) =====

export interface ReferencePrice {
  id: string;
  supplier: 'signia' | 'resound' | 'starkey' | 'biotone';
  product_name: string;
  category: 'RIC' | 'Intra' | 'BTE' | 'Accessoire' | 'Entretien';
  price_ht: number;
  valid_from: string;
  valid_to: string | null;
  catalog_id: string | null;
  is_manual: boolean;
  created_at: string;
  updated_at: string;
}

export interface ProductMapping {
  id: string;
  supplier: 'signia' | 'resound' | 'starkey';
  code_article: string;
  description_edi: string | null;
  matched_product_id: string | null;
  matched_product_name: string | null;
  confidence: 'exact' | 'keyword' | 'claude' | 'excluded' | 'manual';
  validated: boolean;
  status: 'matched' | 'unknown' | 'manual' | null;
  created_at: string;
}

export interface CentreCode {
  id: string;
  supplier: 'signia' | 'resound' | 'starkey';
  code: string;
  name: string;
  is_suc: boolean;
  created_at: string;
}

export interface Analysis {
  id: string;
  month: string;
  supplier: 'signia' | 'resound' | 'starkey';
  file_name: string | null;
  total_lines: number;
  filtered_lines: number;
  matched_lines: number;
  unmatched_lines: number;
  total_discrepancies: number;
  total_overcharged: number;
  discrepancy_count: number;
  status: 'pending' | 'processing' | 'done' | 'error';
  created_at: string;
  updated_at: string;
}

export interface AnalysisLine {
  id: string;
  analysis_id: string;
  centre: string | null;
  code_article: string | null;
  description: string | null;
  quantity: number;
  invoiced_price: number | null;
  negotiated_price: number | null;
  discrepancy: number | null; // GENERATED column
  matched_product: string | null;
  match_method: 'exact' | 'keyword' | 'claude' | 'unmatched' | null;
  invoice_number: string | null;
  famille: string | null;
  created_at: string;
}

export interface EmailDraft {
  id: string;
  analysis_id: string;
  supplier: 'signia' | 'resound' | 'starkey';
  subject: string | null;
  body: string | null;
  created_at: string;
}

// ===== Parser output =====

export interface ParsedEDILine {
  centre_code: string;
  centre_name: string;
  code_article: string;
  description: string;
  quantity: number;
  unit_price: number;
  discount_pct: number;
  invoice_number: string;
  invoice_date: string;
  sign: string;
  famille: string;
}

export interface ParsedPDFLine {
  code_article: string;
  description: string;
  unit_price: number;
  quantity: number;
}

// ===== UI types =====

export type Supplier = 'signia' | 'resound' | 'starkey';

export interface MonthStatus {
  month: string;
  signia: 'pending' | 'uploaded' | 'done';
  resound: 'pending' | 'uploaded' | 'done';
  starkey: 'pending' | 'uploaded' | 'done';
}

export interface SupplierSummary {
  supplier: Supplier;
  total_lines: number;
  discrepancy_count: number;
  total_overcharged: number;
}

export interface UploadState {
  supplier: Supplier;
  file: File | null;
  status: 'pending' | 'uploaded' | 'analyzing' | 'done';
  lines?: ParsedEDILine[];
}
