// apps/web/src/server/invoicing/types.ts
import type { z } from 'zod';

export interface InvoiceCreateArgs {
  vendor: { id: string; name: string; vatNumber?: string };
  buyer: { id: string; name: string; email: string };
  purchase: { id: string; createdAt: Date };
  lineItems: Array<{ description: string; qty: number; unitAgorot: number }>;
  grossAgorot: number;
  vatAgorot: number;
}

export interface InvoiceCreateResult {
  documentId: string;
  documentNumber: string;
  documentUrl: string;
}

/**
 * Per-vendor invoice provider for ITEM purchases.
 *
 * Distinct from the legacy `InvoiceProvider` in ./provider.ts, which models
 * platform-side tax-doc issuance for COUPON/GROUP. Both coexist until the
 * legacy flow is migrated onto this registry.
 */
export interface VendorInvoiceProvider {
  kind: string;
  credentialsSchema: z.ZodTypeAny;
  validateCredentials(creds: unknown): Promise<{ ok: true } | { ok: false; reason: string }>;
  createInvoice(args: InvoiceCreateArgs): Promise<InvoiceCreateResult>;
  voidInvoice?(documentId: string): Promise<void>;
}
