import { SmrtObject } from '@happyvertical/smrt-core'; import { ReferralOptions, ReferralStatus } from '../types.js'; export declare class Referral extends SmrtObject { /** Tenant ID for multi-tenant isolation (nullable → global referrals). */ tenantId: string | null; /** The Referrer credited with the introduction. Required. */ referrerId: string; /** The ReferralProgram the referral belongs to. Required. */ programId: string; /** AttributionPolicy key resolved at attribution ('' until attributed). */ policyKey: string; /** AttributionPolicy version resolved at attribution (0 until attributed). */ policyVersion: number; /** * Lifecycle status — see the module transition map. Mutate via the * transition methods; the save-time guard rejects illegal edges. */ status: ReferralStatus; /** * Generic qualifying target: what the introduction became/points at — * `('lead', )`, `('opportunity', )`, `('client', )`, * `('subscription', )`, … This module attaches no semantics to it. */ targetKind: string; /** Identifier within the {@link targetKind} namespace. */ targetId: string; /** * Credit share (0–1) this referral carries. `1.0` for sole attribution; * split attribution creates sibling Referrals whose fractions sum to 1.0 * sharing one {@link splitGroupId}. Flows into Commission * `shareFraction` at earning time. */ creditFraction: number; /** Groups the sibling referrals of one split. Empty for unsplit rows. */ splitGroupId: string; /** The winning ReferralTouch behind the attribution ('' for touchless awards). */ primaryTouchId: string; /** When the referral was attributed. */ attributedAt: Date | null; /** When the referral was qualified. */ qualifiedAt: Date | null; /** * When an attributed-but-unqualified referral lapses. Stamped at * attribution (`attributedAt + policy.windowDays`); enforced by * `ReferralCollection.sweepExpired()`. */ expiresAt: Date | null; /** * The ReferralTermSnapshot frozen at qualification ('' until qualified). * Requalification repoints this at a NEW snapshot; old snapshots remain * as history. * * Deliberately a PLAIN string reference (not `@foreignKey`): the * snapshot's own `referralId` FK carries the relationship, and declaring * both directions would put a cycle in the model graph (breaking the * registry's topological initialization order). Services fetch the * snapshot by id explicitly. */ snapshotId: string; /** * Free-form JSON object stored as a string. Use * {@link getMetadata}/{@link setMetadata} instead of parsing manually. */ metadata: string; constructor(options?: ReferralOptions); /** * Re-coerce date fields after the framework reapplies raw option values * and record the loaded status for the save-time transition guard. */ initialize(): Promise; isAttributed(): boolean; isQualified(): boolean; /** Whether the referral sits in a terminal status. */ isTerminal(): boolean; /** Parse {@link metadata}; returns `{}` on malformed content. */ getMetadata(): Record; /** Serialize and store {@link metadata}. */ setMetadata(data: Record): void; /** Transition `pending → under_review` (conflict parked for humans). */ markUnderReview(): void; /** * Transition `pending | under_review → attributed` and stamp * {@link attributedAt}. */ markAttributed(at?: Date): void; /** Transition `attributed → qualified` and stamp {@link qualifiedAt}. */ markQualified(at?: Date): void; /** * Transition to `disqualified` (terminal). Legal from every non-terminal * status — including `qualified` (the rare clawback path). */ disqualify(): void; /** Transition `pending | attributed → expired` (terminal). */ markExpired(): void; /** * Validate the status transition before persisting, then save. A forged * `status` (e.g. un-expiring a referral or skipping straight to * qualified) is rejected regardless of how the instance was constructed. */ save(): Promise; /** * Resolve the AUTHORITATIVE prior status from the database; fall back to * the loaded-status WeakMap only when the DB is unavailable (commerce * pattern — an upsert via `create({ id, _skipLoad: true })` can't * sidestep the guard). */ private resolvePriorStatus; private assertStatusTransition; private static coerceDate; } export default Referral; //# sourceMappingURL=Referral.d.ts.map