export type CustomerStatus = "lead" | "active" | "inactive" | "blocked" | "archived";
export type CustomerType = "company" | "private" | "public_sector" | "partner" | "supplier";
export type AddressType = "billing" | "shipping" | "primary" | "other";
export type CustomerImportMode = "create_only" | "update_existing" | "upsert";
export type CustomerImportAction = "create" | "update" | "skip" | "error";

export interface CustomerAddress {
  id: number;
  customer_id: number;
  type: AddressType;
  street: string;
  postal_code: string;
  city: string;
  state: string;
  country: string;
  is_primary: boolean;
  created_at: string;
  updated_at: string;
}

export interface CustomerContact {
  id: number;
  customer_id: number;
  first_name: string;
  last_name: string;
  position: string;
  email: string;
  phone: string;
  mobile: string;
  is_primary: boolean;
  notes: string;
  created_at: string;
  updated_at: string;
}

export interface Customer {
  id: number;
  customer_number: string;
  company_name: string;
  legal_name: string;
  customer_type: CustomerType;
  status: CustomerStatus;
  industry: string;
  website: string;
  email: string;
  phone: string;
  tax_number: string;
  vat_id: string;
  notes: string;
  addresses: CustomerAddress[];
  contacts: CustomerContact[];
  created_at: string;
  updated_at: string;
}

export type CustomerPayload = {
  customer_number: string;
  company_name: string;
  legal_name: string;
  customer_type: CustomerType;
  status: CustomerStatus;
  industry: string;
  website?: string | null;
  email?: string | null;
  phone: string;
  tax_number: string;
  vat_id: string;
  notes: string;
  addresses: CustomerAddressPayload[];
};

export type CustomerAddressPayload = {
  type: AddressType;
  street: string;
  postal_code: string;
  city: string;
  state: string;
  country: string;
  is_primary: boolean;
};

export type CustomerContactPayload = {
  first_name: string;
  last_name: string;
  position: string;
  email?: string | null;
  phone: string;
  mobile: string;
  is_primary: boolean;
  notes: string;
};

export interface CustomerImportIssue {
  row: number;
  field: string;
  message: string;
}

export interface CustomerImportPreviewRow {
  row: number;
  customer_number: string;
  company_name: string;
  action: CustomerImportAction;
  errors: CustomerImportIssue[];
  warnings: CustomerImportIssue[];
}

export interface CustomerImportSummary {
  total_rows: number;
  valid_rows: number;
  error_count: number;
  warning_count: number;
  duplicate_count: number;
  create_count: number;
  update_count: number;
  skip_count: number;
}

export interface CustomerImportPreviewResponse {
  mode: CustomerImportMode;
  summary: CustomerImportSummary;
  rows: CustomerImportPreviewRow[];
  errors: CustomerImportIssue[];
  warnings: CustomerImportIssue[];
  duplicates: CustomerImportIssue[];
}

export interface CustomerImportCommitResponse {
  mode: CustomerImportMode;
  summary: CustomerImportSummary;
  created: number;
  updated: number;
  skipped: number;
}
