import { SmrtObject } from '@happyvertical/smrt-core'; import { CommissionBasis, CommissionCalculationTrace, CommissionOptions, CommissionStatus } from '../types.js'; export declare class Commission extends SmrtObject { /** Tenant ID for multi-tenant isolation (nullable → global rows). */ tenantId: string | null; /** The {@link Earner} this commission belongs to. Required. */ earnerId: string; /** The {@link EarningEvent} evidence row this commission derives from. */ earningEventId: string | null; /** Snapshot reference: plan key at calculation time. */ planKey: string; /** Snapshot reference: plan version at calculation time. */ planVersion: number; /** Which plan component produced this commission. */ componentKey: string; /** * Generic polymorphic reference to the terms snapshot that governed the * calculation (e.g. the referrals module sets * `('referral_term_snapshot', )`). Free-form; this module attaches no * semantics beyond recording it in the dedupe key and trace. */ termsSnapshotKind: string; /** Id of the terms snapshot named by {@link termsSnapshotKind}. */ termsSnapshotId: string; /** How {@link baseAmountCents} was resolved from the event. */ basis: CommissionBasis; /** Base amount the rate was applied to, in integer cents. */ baseAmountCents: number; /** Rate applied (0–1). Recorded as `0` for `fixed`-basis commissions. */ rate: number; /** Split share applied (0–1). `1.0` for unsplit commissions. */ shareFraction: number; /** * Groups the sibling commissions of one split — every earner sharing an * event/component carries the same `splitGroupId`. Empty for unsplit rows. */ splitGroupId: string; /** The earned amount in integer cents. */ amountCents: number; /** ISO 4217 currency (copied from the earning event). */ currency: string; /** * Lifecycle status — strict chain `pending → earned → approved → payable * → paid`. Mutate via the transition methods; the save-time guard rejects * illegal edges. */ status: CommissionStatus; /** * End of the clearing window (refund/chargeback holdback). `null` means * no clearing applies — the commission is immediately sweepable to * `earned` (see `CommissionSettlementService.sweepClearing`). */ clearingEndsAt: Date | null; /** When the commission transitioned to `earned`. */ earnedAt: Date | null; /** When the commission transitioned to `approved`. */ approvedAt: Date | null; /** When the commission transitioned to `payable`. */ payableAt: Date | null; /** When the commission transitioned to `paid`. */ paidAt: Date | null; /** * The {@link CommissionPayout} batch that settled this commission. Empty * until a payout batch stamps it. */ payoutId: string | null; /** Copied from the earning event for reporting (generic source pair). */ sourceKind: string; /** Copied from the earning event for reporting. */ sourceId: string; /** * JSON-string {@link CommissionCalculationTrace} — everything needed to * reproduce {@link amountCents}. Use {@link getCalculationTrace} / * {@link setCalculationTrace}. */ calculationTrace: string; /** * Idempotency natural key — * `` `${event.dedupeKey}:${terms}:${componentKey}:${earnerId}:${occurrenceIndex}` `` * (see `CommissionCalculationService`). Required. */ dedupeKey: string; /** Additional metadata as a JSON string. */ metadata: string; constructor(options?: CommissionOptions); /** * 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; isEarned(): boolean; isApproved(): boolean; isPayable(): boolean; isPaid(): boolean; /** `true` once a payout batch has stamped {@link payoutId}. */ isSettled(): boolean; /** * `pending → earned` (clearing window passed). Stamps {@link earnedAt}. * Does NOT save — the caller saves. */ markEarned(now?: Date): void; /** * `earned → approved` (operator/automation approved the earning). * Stamps {@link approvedAt}. Does NOT save — the caller saves. */ approve(now?: Date): void; /** * `approved → payable` (released for the next payout batch). * Stamps {@link payableAt}. Does NOT save — the caller saves. */ markPayable(now?: Date): void; /** * `payable → paid` (its payout batch completed). Stamps {@link paidAt}. * Does NOT save — the caller saves. */ markPaid(now?: Date): void; private assertTransitionFrom; /** Parse {@link calculationTrace}; returns `null` on empty/invalid JSON. */ getCalculationTrace(): CommissionCalculationTrace | null; /** Serialize and store {@link calculationTrace}. */ setCalculationTrace(trace: CommissionCalculationTrace): void; /** Parse {@link metadata}; returns `{}` on empty/invalid JSON. */ getMetadata(): Record; /** Serialize and store {@link metadata}. */ setMetadata(data: Record): void; /** * Save-time state-machine guard (commerce pattern). Validates the status * transition against the AUTHORITATIVE prior persisted status — re-read * from the database so a `create({ id: , _skipLoad: true })` * upsert is correctly treated as an update rather than a guard-free new * row. Brand-new rows may start in any status (fixtures/imports); a * persisted row may only advance one legal step. */ save(): Promise; /** * Refuse a save whose `dedupeKey` already belongs to a DIFFERENT row — * commissions are audit rows, and the natural-key upsert would let a * fresh instance (generated `create`, or the loser of a calculation * race) overwrite the persisted amount/status and rotate the row id. * `CommissionCalculationService` treats this refusal as "someone else * already earned it" and returns the existing row. */ private assertDedupeKeyNotTaken; private resolvePriorStatus; private assertStatusTransition; private static coerceDate; } export default Commission; //# sourceMappingURL=Commission.d.ts.map