/**
 * Outbound Sync Handler
 *
 * Listens for work-lifecycle domain events on the EventBus and pushes
 * changes to external issue trackers (Linear, Shortcut, etc.) via their
 * respective adapters.
 *
 * Subscribes to work:* events (provider-agnostic), NOT ticket:* events.
 * The work-lifecycle adapter layer translates provider-specific events
 * into these domain events, keeping PMO as just another provider.
 */
import Database from 'better-sqlite3';
import type { ExternalMappingProvider } from './types.js';
/**
 * Result of an outbound sync attempt for a single event.
 */
export interface OutboundSyncResult {
    provider: ExternalMappingProvider;
    success: boolean;
    error?: string;
}
/**
 * OutboundSyncHandler subscribes to work-lifecycle domain events and
 * pushes changes to mapped external providers. It is fire-and-forget:
 * sync failures are logged but never block the caller.
 */
export declare class OutboundSyncHandler {
    private unsubscribers;
    private db;
    private mappingStore;
    constructor(db: Database.Database);
    /**
     * Start listening for work-lifecycle events on the global EventBus.
     * Subscribes to work:* domain events, not provider-specific ticket:* events.
     * Call `stop()` to unsubscribe.
     */
    start(): void;
    /**
     * Stop listening for events and clean up.
     */
    stop(): void;
    /**
     * Handle a work status change by syncing to all mapped external providers.
     * Skips syncing back to the source provider to avoid loops.
     */
    private handleStatusChanged;
    /**
     * Handle a PR creation by syncing to all mapped external providers.
     * Skips syncing back to the source provider to avoid loops.
     */
    private handlePRLinked;
    /**
     * Handle a PR merge by syncing to all mapped external providers.
     * Transitions the linked external issue to a completed state.
     */
    private handlePRMerged;
    /**
     * Sync a status change to Linear if the work item has a Linear mapping.
     */
    private syncStatusToLinear;
    /**
     * Sync a PR link to Linear if the work item has a Linear mapping.
     */
    private syncPRToLinear;
    /**
     * Sync a PR merge to Linear if the work item has a Linear mapping.
     * Transitions the issue to "completed" state and posts a merge comment.
     */
    private syncMergeToLinear;
    /**
     * Sync status changes to providers tracked via the external_execution_map table.
     * Updates the state snapshot so that future inbound syncs can detect drift.
     * Skips the source provider to avoid sync loops.
     */
    private syncStatusToMappedProviders;
    /**
     * Record a PR URL in all external mappings for a work item.
     */
    private recordPRInMappings;
    /**
     * Record a PR merge in all external mappings for a work item.
     */
    private recordMergeInMappings;
    /**
     * Find external execution mappings associated with a work item.
     * Checks the latest_state_snapshot for work item ID references.
     */
    private findMappingsForWorkItem;
}
/**
 * Find the best matching Linear workflow state for a status change.
 * Prefers an exact name match (e.g. "In Progress" → "In Progress") over
 * a category-type match (e.g. 'started') to avoid ambiguity when multiple
 * states share the same category.
 */
export declare function findMatchingLinearState(states: Array<{
    id: string;
    name: string;
    type: string;
}>, statusName: string | null, categoryType: string): {
    id: string;
    name: string;
    type: string;
} | undefined;
/**
 * Initialize and start the outbound sync handler.
 * Safe to call multiple times — subsequent calls are no-ops.
 */
export declare function initOutboundSync(db: Database.Database): OutboundSyncHandler;
/**
 * Stop the outbound sync handler (primarily for testing).
 */
export declare function stopOutboundSync(): void;
