import type { LTMilestone } from './task';
/**
 * System event type patterns.
 *
 * System events use structured subjects with embedded resource IDs:
 *   `system.workflow.{workflowId}.completed`
 *   `system.escalation.{escalationId}.claimed`
 *   `system.activity.{workflowId}.{activityName}.failed`
 *
 * On the wire (NATS): `lt.events.system.workflow.abc123.completed`
 * Dashboard subscribes: `lt.events.system.>` for all system events,
 * or `lt.events.system.workflow.abc123.>` for a specific workflow.
 *
 * The `*` segments in these patterns are replaced with actual IDs at publish time.
 */
export type LTSystemEventPattern = `system.task.${string}.created` | `system.task.${string}.started` | `system.task.${string}.completed` | `system.task.${string}.escalated` | `system.task.${string}.failed` | `system.escalation.${string}.created` | `system.escalation.${string}.resolved` | `system.escalation.${string}.claimed` | `system.escalation.${string}.released` | `system.workflow.${string}.started` | `system.workflow.${string}.completed` | `system.workflow.${string}.failed` | `system.activity.${string}.${string}.started` | `system.activity.${string}.${string}.completed` | `system.activity.${string}.${string}.failed` | `system.knowledge.${string}.stored` | `system.knowledge.${string}.deleted` | 'system.file.stored' | 'system.file.deleted' | `system.agent.${string}.started` | `system.agent.${string}.completed` | `system.agent.${string}.failed` | `system.agent.${string}.status_changed` | `system.agent.${string}.triggers_changed` | `system.milestone.${string}`;
/** @deprecated Use LTSystemEventPattern for system events. Kept for backward compat. */
export type LTEventType = LTSystemEventPattern;
/**
 * Application-defined event type.
 * Convention: `app.{namespace}.{entity}.{action}`
 * Examples: `app.epic.apis.createorder.error`, `app.vendor.schema.drift`
 */
export type LTAppEventType = `app.${string}`;
/**
 * Payload published through the events system.
 */
export interface LTEvent {
    /** Idempotent event identifier. Auto-generated by eventRegistry.publish() if omitted. */
    id?: string;
    /** Event classification — structured subject for system events, free-form for app events */
    type: LTSystemEventPattern | string;
    /** Where the event originated: 'interceptor' | 'orchestrator' | 'activity' */
    source: string;
    /** The workflow instance that produced this event */
    workflowId: string;
    /** The workflow function name */
    workflowName: string;
    /** The task queue the workflow ran on */
    taskQueue: string;
    /** The task ID (present when orchestrated) */
    taskId?: string;
    /** The escalation ID (present for escalation events) */
    escalationId?: string;
    /** The origin ID — root process lineage */
    originId?: string;
    /** Task or workflow status after this event */
    status?: string;
    /** The activity name (present when source is 'activity') */
    activityName?: string;
    /** Milestones reported by the workflow */
    milestones?: LTMilestone[];
    /** Optional result data */
    data?: Record<string, any>;
    /** ISO 8601 timestamp */
    timestamp: string;
}
/**
 * Pluggable event adapter interface.
 *
 * Implement this to route Long Tail events to your pub/sub system
 * (NATS, SNS, GCP Pub/Sub, Kafka, etc.).
 *
 * Usage:
 * ```typescript
 * import { LTEventAdapter, LTEvent } from '@hotmeshio/long-tail';
 *
 * class MySnsAdapter implements LTEventAdapter {
 *   async connect() { /* init SNS client *​/ }
 *   async publish(event: LTEvent) { /* publish to SNS *​/ }
 *   async disconnect() { /* cleanup *​/ }
 * }
 * ```
 */
export interface LTEventAdapter {
    /** Initialize the connection (called once during startup) */
    connect(): Promise<void>;
    /** Publish an event (fire-and-forget semantics; errors are swallowed by the registry) */
    publish(event: LTEvent): Promise<void>;
    /** Graceful shutdown */
    disconnect(): Promise<void>;
    /**
     * Bridge cross-container events to the in-process callback adapter.
     *
     * Implemented by transport adapters that support cross-process delivery
     * (NATS, SNS, GCP Pub/Sub, Kafka, etc.). When set, the adapter subscribes
     * to all events on the bus and forwards events from other containers to
     * the local callback adapter for agent trigger dispatch.
     *
     * The adapter must de-duplicate its own events (e.g., via an origin ID)
     * to prevent the publishing container from re-processing its own events.
     */
    setCallbackBridge?(adapter: LTEventAdapter): void;
}
