import type { ShipmentType } from '@/lib/types';

export type PurchaseJournalPostingInput = {
  orderNumber: string;
  supplierId: string;
  supplierName: string;
  totalAmountBase: number;
  taxAmountBase: number;
  discountAmountBase: number;
  amountPaidBase: number;
  createdBy: string;
  /** Original transaction currency code (e.g. "USD"). If omitted, base currency is assumed. */
  currencyCode?: string;
  opts?: {
    invoiceId?: string;
    shipmentId?: string;
    shipmentType?: ShipmentType;
    paymentMethods?: any[];
    fxRate?: number;
  };
};

export type ShipmentGrniInput = {
  shipmentOrderNumber: string;
  shipmentId: string;
  supplierId: string;
  supplierName: string;
  /** Net purchase amount in base currency (excluding tax) */
  totalAmountBase: number;
  createdBy: string;
};

export interface PurchaseAccountingPort {
  postPurchaseOrderJournalEntry(input: PurchaseJournalPostingInput): Promise<void>;

  /**
   * Creates a draft GRNI (Goods Received Not Invoiced) journal entry for a shipment.
   * Dr 5110 Purchases (provisional), Cr 2115 GRNI Payable — status: draft
   */
  postShipmentGrniEntry(input: ShipmentGrniInput): Promise<void>;

  /**
   * Settles (reverses) GRNI entries for the given shipment IDs when a tax invoice is posted.
   * Dr 2115 GRNI Payable, Cr 5110 Purchases — posted as final entry.
   */
  settleGrniEntries(shipmentIds: string[], invoiceOrderNumber: string, createdBy: string): Promise<void>;
}
