import { SmrtObject } from '@happyvertical/smrt-core'; import { CommissionPayoutOptions, CommissionPayoutStatus, PayoutMethod } from '../types.js'; export declare class CommissionPayout extends SmrtObject { /** Tenant ID for multi-tenant isolation (nullable → global payouts). */ tenantId: string | null; /** The {@link Earner} being paid. Required. */ earnerId: string; /** Start of the settlement period this batch covers (informational). */ periodStart: Date | null; /** End of the settlement period this batch covers (informational). */ periodEnd: Date | null; /** Σ amountCents of the Commissions this batch settled (integer cents). */ commissionTotalCents: number; /** * Σ signed amountCents of the Adjustments this batch settled (integer * cents; clawbacks make it negative). */ adjustmentTotalCents: number; /** * Net amount remitted — must equal * `commissionTotalCents + adjustmentTotalCents` (enforced on save). */ totalAmountCents: number; /** ISO 4217 currency of the batch. */ currency: string; /** Delivery method for this batch (defaulted from the Earner). */ payoutMethod: PayoutMethod; /** * Lifecycle status — see the class doc. Mutate via {@link approve} / * {@link markProcessing} / {@link complete} / {@link fail} / * {@link resetFromFailed}. */ status: CommissionPayoutStatus; /** * Payment reference recorded at completion (check number, transfer id, * …). Cleared by {@link resetFromFailed}. */ paymentReference: string; /** * Opaque payout-provider reference (processor batch id, remittance file * id, …). Retained across failure/reset for audit. */ providerRef: string; /** When the payout completed. */ paidAt: Date | null; /** * Optional link to the commerce Invoice that papers this payout * (cross-package string reference — never a DDL foreign key). */ invoiceId: string; /** Operator notes — approval memos, failure reasons (append-only). */ notes: string; /** * Idempotency natural key. Required. The payout service defaults it to * `` `${earnerId}:${currency}:${periodEnd ISO date}` `` when the caller * doesn't supply one. */ idempotencyKey: string; /** * DERIVED single-source stamp: when every member commission — and every * member adjustment's parent commission — shares exactly one non-empty * `(sourceKind, sourceId)`, that source is stamped here; otherwise both * stay `''` (mixed-source, unknown-source, or empty membership). The * payout service maintains the stamp from VERIFIED claimed membership at * batch/repair time (`restampPayoutSource` is the backfill for payouts * minted before the stamp existed). It is the index behind the * source-scoped payout-history listing, which still re-verifies * membership per page — never an authorization input by itself. */ sourceKind: string; /** Id half of the derived single-source stamp — see {@link sourceKind}. */ sourceId: string; /** Additional metadata as a JSON string. */ metadata: string; constructor(options?: CommissionPayoutOptions); /** * Re-coerce timestamp fields after the framework reapplies raw option / * hydrated row values, and record the loaded status for the save guard. */ initialize(): Promise; isPending(): boolean; isApproved(): boolean; isProcessing(): boolean; isCompleted(): boolean; isFailed(): boolean; isRejected(): boolean; /** `pending → approved`. Does NOT save — the caller saves. */ approve(): void; /** `approved → processing`. Does NOT save — the caller saves. */ markProcessing(): void; /** * `processing → completed`. Requires a payment reference — a completed * payout with no reference is untraceable. Stamps {@link paidAt}. * Does NOT save — the caller saves. */ complete(paymentReference: string, now?: Date): void; /** * `pending | approved → rejected` (operator declined the batch before * remittance started). Terminal — there is no reset from rejected; the * released membership settles through a future batch. Requires a reason, * appended to {@link notes}. This mutates the payout only: use * `CommissionPayoutService.transitionPayoutForSource` to reject, which * also RELEASES the batch's membership (clears `payoutId` on its * commissions and adjustments) in the same operation — a rejected payout * that kept its rows stamped would strand them unsettleable forever. * Does NOT save — the caller saves. */ reject(reason: string): void; /** * `approved | processing → failed`. Appends the reason to {@link notes}. * Does NOT save — the caller saves. */ fail(reason: string): void; /** * Operator-driven reset: `failed → pending` after fixing whatever broke. * Clears {@link paymentReference} and {@link paidAt} (the next attempt * gets fresh ones) but RETAINS {@link providerRef} and {@link notes} for * audit. The only path out of `failed`. Does NOT save — the caller saves. */ resetFromFailed(): void; /** Parse {@link metadata}; returns `{}` on empty/invalid JSON. */ getMetadata(): Record; /** Serialize and store {@link metadata}. */ setMetadata(data: Record): void; /** * Save with two guards (commerce pattern): * * 1. **Totals invariant** — `totalAmountCents` must equal * `commissionTotalCents + adjustmentTotalCents` (exact integer * arithmetic, no epsilon). * 2. **Status transition** — validated against the AUTHORITATIVE prior * persisted status (re-read from the database so a * `create({ id, _skipLoad: true })` upsert can't sidestep the guard). * A `completed` payout additionally requires a payment reference, * matching {@link complete}'s invariant, regardless of how the status * was set. */ save(): Promise; /** Throws when the totals invariant doesn't hold. */ validateTotals(): void; private resolvePriorStatus; private assertStatusTransition; private static coerceDate; } export default CommissionPayout; //# sourceMappingURL=CommissionPayout.d.ts.map