import { SmrtCollection } from '@happyvertical/smrt-core'; import { Lead } from '../models/Lead.js'; import { Opportunity } from '../models/Opportunity.js'; import { SalesActivity } from '../models/SalesActivity.js'; import { LeadStatus, MergeLeadsParams, MergeLeadsResult, QualifyLeadParams } from '../types.js'; export declare class LeadCollection extends SmrtCollection { static readonly _itemClass: typeof Lead; private opportunityCollectionPromise; private pipelineCollectionPromise; private activityCollectionPromise; /** Sibling opportunity collection sharing this collection's DB connection. */ private getOpportunityCollection; /** Sibling pipeline collection sharing this collection's DB connection. */ private getPipelineCollection; /** Sibling activity collection sharing this collection's DB connection. */ private getActivityCollection; /** Leads in a given lifecycle status, newest first. */ findByStatus(status: LeadStatus): Promise; /** Leads owned by a given sales rep, newest first. */ findByOwner(ownerRepId: string): Promise; /** * Qualify a lead into an Opportunity. * * Transitions the lead to `qualified` (stamping `qualifiedAt` once) and * creates an Opportunity at the FIRST stage of the target pipeline — * `pipelineId` when given, otherwise the seeded default pipeline * (`ensureDefaultPipeline()`). The opportunity adopts the first stage's * probability, copies the lead's `sourceKind`/`sourceId` for reporting, * and defaults its name/owner from the lead. A `qualification` * SalesActivity is written on BOTH the lead and the opportunity. * * IDEMPOTENT: when the lead is already `qualified` and an opportunity * exists for it, that opportunity is returned unchanged (no new rows, no * new activities). A qualified lead with no opportunity (interrupted * earlier run) is healed by creating the missing opportunity. * * Illegal source statuses are rejected by the lead's save-time transition * guard (`disqualified`/`merged` leads cannot be qualified). * * @returns The (existing or newly created) opportunity */ qualify(params: QualifyLeadParams): Promise; /** * Audited duplicate merge: fold the `loserId` lead into the `winnerId` * lead. * * Validations: the ids must differ, both leads must exist, the loser must * not already be merged, the winner must not itself be merged (merge into * the chain head instead), and the merge must not create a * `mergedIntoId` cycle. * * Effects: * - EMPTY winner contact fields (`contactName`/`email`/`phone`/ * `organizationName`) are filled from the loser; non-empty winner data * is never overwritten; * - the loser's acquisition context is appended into the winner's under a * `mergedSources` array (both histories preserved verbatim); * - the loser becomes terminal: `status: 'merged'` + * `mergedIntoId: winnerId`; * - a `merge` SalesActivity is written on BOTH leads, each carrying a full * pre-merge loser snapshot in metadata; * - the loser's existing activities STAY attached to the loser (history * preserved in place) — read the combined trail via * {@link activitiesIncludingMerged}. */ mergeLeads(params: MergeLeadsParams): Promise; /** * The lead's activity trail INCLUDING the trails of every lead merged into * it, transitively (losers keep their own activities; this read * re-assembles the full history across `mergedIntoId` chains). * * Traversal is breadth-first over merge children with a visited-set guard, * so malformed cyclic data cannot loop. Results are in chronological * order. */ activitiesIncludingMerged(leadId: string): Promise; } export default LeadCollection; //# sourceMappingURL=LeadCollection.d.ts.map