import { SmrtObject } from '@happyvertical/smrt-core'; import { ReferralAgreementApprovalMode, ReferralAgreementOptions, ReferralAgreementStatus } from '../types.js'; export declare class ReferralAgreement extends SmrtObject { /** Tenant ID for multi-tenant isolation (nullable → global agreements). */ tenantId: string | null; /** The Referrer bound by this agreement. Required. */ referrerId: string; /** The ReferralProgram the agreement applies to. Required. */ programId: string; /** Monotonic version within `(referrerId, programId)`. */ version: number; /** * Lifecycle status — see the module transition map. Mutate via * {@link activate} / {@link supersede} / {@link terminate}. */ status: ReferralAgreementStatus; /** Start of the effective window (`null` = effective immediately). */ effectiveFrom: Date | null; /** * End of the effective window (`null` = open-ended). Deliberately NOT * frozen: end-dating an active agreement is a legitimate operation. */ effectiveTo: Date | null; /** * The commissions-module CommissionPlan key these terms bind. Required to * activate. */ commissionPlanKey: string; /** * Pinned plan version. `0` (default) means "resolve the latest ACTIVE * version at qualification time and pin it in the ReferralTermSnapshot"; * `> 0` pins a specific version now. */ commissionPlanVersion: number; /** * Clearing window in days applied to commissions earned under these * terms (refund/chargeback holdback). Frozen into every snapshot. */ clearingDays: number; /** How earned commissions are approved downstream. */ approvalMode: ReferralAgreementApprovalMode; /** Current provider workflow while this version is being signed. */ executionId: string | null; /** Immutable executed evidence required before this version can activate. */ executedAgreementId: string | null; /** * Free-form JSON object stored as a string. Use * {@link getMetadata}/{@link setMetadata} instead of parsing manually. */ metadata: string; constructor(options?: ReferralAgreementOptions); /** * Re-coerce date fields after the framework reapplies raw option values, * record the loaded status for the transition guard, and capture the * frozen terms snapshot when the row arrived already non-draft * (superseded / terminated history can't be rewritten either). */ initialize(): Promise; isDraft(): boolean; isActive(): boolean; /** * Whether the effective window contains `at` (`effectiveFrom` null = * always started; `effectiveTo` null = open-ended). Status is NOT part of * this check — combine with {@link isActive}. */ isEffectiveAt(at: Date): boolean; /** Parse {@link metadata}; returns `{}` on malformed content. */ getMetadata(): Record; /** Serialize and store {@link metadata}. */ setMetadata(data: Record): void; /** * Transition `draft → active`. Requires a non-empty * {@link commissionPlanKey} — an agreement without bound terms cannot * govern qualification. */ activate(): void; /** Bind the provider workflow to an unsigned draft. */ bindExecution(executionId: string): void; /** Bind immutable completed evidence to an unsigned draft. */ bindExecutedAgreement(executedAgreementId: string): void; /** Transition `active → superseded` (a newer version took over). */ supersede(): void; /** Transition `draft | active → terminated` (terminal). */ terminate(): void; /** * Save with two guards (CommissionPlan pattern): * * 1. **Status transition** — the about-to-be-written status must be a * legal edge from the authoritative prior persisted status. * 2. **Frozen terms** — once the row has been saved non-draft, the terms * fields must match the captured snapshot. Amend by inserting a new * version instead. * * Activating saves also re-require {@link commissionPlanKey}. */ save(): Promise; /** * Refuse a save whose `(referrerId, programId, version)` natural key * already belongs to a DIFFERENT row — the frozen-terms guard is * instance-local, so a fresh instance would otherwise upsert over the * persisted agreement (replacing legally frozen referral terms without * an amendment, and rotating the row id). Edit drafts by hydrating * them; change terms with * `ReferralAgreementCollection.createAmendment()`. */ private assertNaturalKeyNotTaken; private resolvePriorStatus; private assertStatusTransition; private assertFrozenTermsUnchanged; private serializeFrozenTerms; private static coerceDate; } export default ReferralAgreement; //# sourceMappingURL=ReferralAgreement.d.ts.map