import { F as ReturnTransitionError, G as isReturnTransitionError, c as Actor, t as OrdersSchema } from "./schema-DKaoubEu.js";
import { PostgresTransaction, TransactionalDatabase } from "@platform-modules/db";
import { RefundRequest, RefundResult, RefundResult as RefundResult$1 } from "@platform-modules/billing";
//#region src/returns/types.d.ts
type ReturnStatus = 'requested' | 'approved' | 'in_transit' | 'received' | 'refunded' | 'rejected';
type RefundLine = {
  orderLineId: string;
  qty: number;
  amount: bigint;
};
type ReturnState = {
  status: ReturnStatus;
  orderId: string;
  lines: RefundLine[];
};
type ReturnCommand = {
  type: 'buyer.request';
  actor: Actor;
} | {
  type: 'buyer.cancel';
  actor: Actor;
} | {
  type: 'vendor.approve';
  actor: Actor;
} | {
  type: 'vendor.reject';
  actor: Actor;
} | {
  type: 'admin.override';
  to: ReturnStatus;
  actor: Actor;
} | {
  type: 'carrier.received';
  actor: Actor;
} | {
  type: 'sla.autoApprove';
  actor: Actor;
};
type ReturnEvent = {
  type: 'return.requested';
} | {
  type: 'return.approved';
} | {
  type: 'return.rejected';
} | {
  type: 'return.cancelled';
} | {
  type: 'return.in_transit';
} | {
  type: 'return.received';
} | {
  type: 'return.refunded';
} | {
  type: 'return.overridden';
  to: ReturnStatus;
};
type RefundPort = (req: RefundRequest) => Promise<RefundResult>;
//#endregion
//#region src/returns/machine.d.ts
declare function decideReturn(state: ReturnState, cmd: ReturnCommand): ReturnEvent[];
//#endregion
//#region src/returns/execute-refund.d.ts
declare function executeRefund(db: TransactionalDatabase<OrdersSchema>, orderId: string, lines: RefundLine[], refund: RefundPort, actor: Actor): Promise<RefundResult$1>;
//#endregion
//#region src/returns/reconcile-stuck-refunds.d.ts
type RefundSweepFailure = {
  intentId: string;
  orderId: string;
  error: unknown;
};
type RefundSweepResult = {
  scanned: number;
  settled: number;
  stillPending: number;
  failures: RefundSweepFailure[];
};
declare function reconcileStuckRefunds(db: TransactionalDatabase<OrdersSchema>, refund: RefundPort, opts?: {
  olderThan?: Date;
  limit?: number;
}): Promise<RefundSweepResult>;
//#endregion
export { type RefundLine, type RefundPort, type RefundRequest, type RefundResult, type RefundSweepFailure, type RefundSweepResult, type ReturnCommand, type ReturnEvent, type ReturnState, type ReturnStatus, ReturnTransitionError, decideReturn, executeRefund, isReturnTransitionError, reconcileStuckRefunds };