// ─── Generic Print Data ─────────────────────────────────────────

export interface GenericPrintData {
  documentTitle: string;
  documentNumber: string;
  date: string;
  dueDate?: string;
  reference?: string;
  partyLabel: string;
  partyName: string;
  partyAddress?: string;
  partyTaxNumber?: string;
  salesperson?: string;
  currency: string;
  items: GenericPrintItem[];
  subtotal: number;
  discountAmount: number;
  taxAmount: number;
  total: number;
  amountPaid?: number;
  balanceDue?: number;
  notes?: string;
  company: any;
  dir: 'rtl' | 'ltr';
  lang: 'ar' | 'en';
  t: (key: string) => string;
  extraFields?: { label: string; value: string }[];
  extraSections?: { title: string; html: string }[];
  /** Whether items use unit_cost (purchases) or unit_price (sales) label */
  priceLabel?: string;
}

export interface GenericPrintItem {
  name: string;
  code?: string;
  description?: string;
  quantity: number;
  unitName?: string;
  unitPrice: number;
  discount?: number;
  discountIsPercent?: boolean;
  tax?: number;
  total: number;
}

// ─── Custom Template ────────────────────────────────────────────

export interface CustomTemplateConfig {
  primaryColor: string;
  accentColor: string;
  fontFamily: string;
  fontSize: number;
  showLogo: boolean;
  showTaxNumber: boolean;
  showReference: boolean;
  showSalesperson: boolean;
  showNotes: boolean;
  showDiscountCol: boolean;
  headerText: string;
  footerText: string;
  paperSize: 'A4' | 'A5' | 'Thermal';
}

export interface CustomTemplate {
  id: string;
  label_ar: string;
  label_en: string;
  base: string;
  config: CustomTemplateConfig;
  customCss: string;
  customBodyHtml: string;
}

export const DEFAULT_TEMPLATE_CONFIG: CustomTemplateConfig = {
  primaryColor: '#1a237e',
  accentColor: '#ffc107',
  fontFamily: "'Segoe UI', Tahoma, Arial, sans-serif",
  fontSize: 12,
  showLogo: true,
  showTaxNumber: true,
  showReference: true,
  showSalesperson: true,
  showNotes: true,
  showDiscountCol: true,
  headerText: '',
  footerText: '',
  paperSize: 'A4',
};

// ─── Document Print Config ──────────────────────────────────────

export interface DocumentPrintConfig {
  documentType: string;
  labelAr: string;
  labelEn: string;
  icon: string;
  settingKeyPrefix: string;
  toGenericData: (doc: any, company: any, dir: string, lang: string, t: Function) => GenericPrintData;
  sampleData: (t: Function) => GenericPrintData;
}

// ─── Built-in Template Registry ─────────────────────────────────

export type GenericPrintTemplateFn = (data: GenericPrintData) => string;

export interface BuiltInTemplate {
  label_ar: string;
  label_en: string;
  fn: GenericPrintTemplateFn;
}
