// AxAssist SDK type definitions. Served at /sdk.d.ts (and /axassist/sdk.d.ts
// via reverse proxy). See /sdk.js for the implementation.

export interface AxAssistInitOptions {
  /** Consumer-side session identifier (UUID). Sent as session_id on every event. */
  sessionId?: string | null;
  /** Persistent visitor identifier shared with the embed. */
  visitorId?: string | null;
  partnerId?: string | null;
  sourceId?: string | null;
  funnelVersion?: number | string | null;
  evftxn?: string | null;
  funnelSlug?: string | null;
  host?: string | null;
  /** Override the API base. Must end with /api/public/axassist/. */
  endpointBase?: string;
}

export interface AxAssistField {
  label: string;
  name: string;
  value: string | number | null | undefined;
}

export interface TrackStepCompletedOptions {
  question?: string;
  type?: "step_completed" | "form_completed";
}

export interface PublishSessionArgs {
  externalSessionId?: string | null;
  visitorId?: string | null;
}

export interface AxAssistApi {
  readonly version: string;
  init(opts: AxAssistInitOptions): void;
  track(event: string, payload?: unknown): void;
  installGtagMirror(): void;
  trackStepCompleted(
    stepKey: string,
    fields: AxAssistField[],
    opts?: TrackStepCompletedOptions
  ): void;
  setSessionMeta(meta: { zip?: string | null }): void;
  publishSession(args: PublishSessionArgs): void;
  notifyLeadSubmitted(leadId: string | null, stepKey?: string): void;
  setLeadId(leadId: string): void;
  setExternalSessionId(id: string): void;
  setVisitorId(id: string): void;
  reportStepCompleted(stepKey: string): void;
  reportFormCompleted(stepKey: string, extra?: Record<string, unknown>): void;
}

export interface AxAssistConfig {
  externalSessionId: string | null;
  visitorId: string | null;
  leadId: string | null;
}

declare global {
  interface Window {
    AxAssist?: AxAssistApi;
    AxAssistConfig?: AxAssistConfig;
  }
}

export {};
