/**
 * V2 Trigger Type Definitions
 *
 * Triggers unify v1's ScheduledMessage, CronTask, and EventSubscription
 * into a single time/signal/compound mechanism that creates or wakes WorkItems.
 *
 * @module types/v2/trigger.types
 */
import type { WorkItem } from './work-item.types.js';
/**
 * What kind of trigger.
 * - time: Cron expression or one-shot delay (replaces ScheduledMessage + CronTask)
 * - signal: Agent event, webhook, or status change (replaces EventSubscription)
 * - compound: Multiple conditions combined with AND/OR
 */
export type TriggerType = 'time' | 'signal' | 'compound';
/** All valid TriggerType values. */
export declare const TRIGGER_TYPES: readonly TriggerType[];
/**
 * Trigger lifecycle statuses.
 */
export type TriggerStatus = 'active' | 'paused' | 'exhausted' | 'cancelled';
/** All valid TriggerStatus values. */
export declare const TRIGGER_STATUSES: readonly TriggerStatus[];
/**
 * Time trigger: fires on schedule or after delay.
 * Replaces v1 ScheduledMessage + CronTask.
 */
export interface TimeTriggerConfig {
    type: 'time';
    /** Cron expression for recurring (e.g., "0 9 * * 1") */
    cronExpression?: string;
    /** IANA timezone (e.g., "America/New_York") */
    timezone?: string;
    /** One-shot delay in ms from creation */
    delayMs?: number;
    /** Fixed ISO8601 datetime for one-shot */
    fireAt?: string;
}
/**
 * Signal trigger: fires when an event matches.
 * Replaces v1 EventSubscription.
 */
export interface SignalTriggerConfig {
    type: 'signal';
    /** Event type to watch for (e.g., "agent:idle", "task:completed") */
    eventType: string;
    /** Optional filter — only fire if event payload matches */
    filter?: Record<string, unknown>;
}
/**
 * Compound trigger: combines sub-conditions with AND/OR.
 */
export interface CompoundTriggerConfig {
    type: 'compound';
    /** How sub-conditions combine */
    operator: 'and' | 'or';
    /** Sub-trigger configs */
    conditions: (TimeTriggerConfig | SignalTriggerConfig)[];
}
/**
 * Discriminated union of all trigger configuration types.
 */
export type TriggerConfig = TimeTriggerConfig | SignalTriggerConfig | CompoundTriggerConfig;
/**
 * What happens when a trigger fires. At least one field should be set.
 */
export interface TriggerAction {
    /** Create a new WorkItem from this template */
    createWorkItem?: Partial<WorkItem>;
    /** Wake (re-queue) an existing WorkItem by ID */
    wakeWorkItemId?: string;
    /** Send a message to a session */
    sendMessage?: {
        target: string;
        message: string;
    };
    /** Run the Reconciler */
    runReconciler?: boolean;
}
/**
 * A Trigger monitors time or signals and produces actions (WorkItems, messages, reconciliation).
 *
 * Triggers are the unified replacement for v1's ScheduledMessage, CronTask,
 * and EventSubscription patterns.
 */
export interface Trigger {
    /** UUID v4 */
    id: string;
    /** What kind of trigger */
    type: TriggerType;
    /** Trigger-specific configuration */
    config: TriggerConfig;
    /** What action to take when the trigger fires */
    action: TriggerAction;
    /** Lifecycle status */
    status: TriggerStatus;
    /** Who created this trigger */
    createdBy: 'user' | 'orchestrator' | 'system' | 'mission';
    /** ISO8601 timestamps */
    createdAt: string;
    lastFiredAt?: string;
    nextFireAt?: string;
    /** Number of times this trigger has fired */
    fireCount: number;
    /** Maximum fires before auto-disable (undefined = unlimited) */
    maxFires?: number;
    /** Auto-cancel after N consecutive idle fires (v1 lesson from issue #131) */
    maxIdleFires: number;
    /** Current count of consecutive idle fires */
    consecutiveIdleFires: number;
    /**
     * Owning team, if this trigger was provisioned from a Team's `triggers` spec.
     * Used by {@link TeamTriggerReconciler} to look up and cancel team-scoped
     * triggers without touching user/mission/system triggers.
     */
    teamId?: string;
    /**
     * Stable name set by the provisioner (e.g. `"youtube-monthly-kickoff"`).
     * The reconciler uses (teamId, name) as the identity key so editing
     * `Team.triggers[].cronExpression` replaces instead of duplicating.
     */
    name?: string;
}
/**
 * Input for creating a new Trigger.
 */
export interface CreateTriggerInput {
    type: TriggerType;
    config: TriggerConfig;
    action: TriggerAction;
    createdBy: 'user' | 'orchestrator' | 'system' | 'mission';
    maxFires?: number;
    maxIdleFires?: number;
    /** Optional owning team (team-scoped triggers) */
    teamId?: string;
    /** Optional stable name for reconciliation-by-identity */
    name?: string;
}
/** Default max idle fires before auto-cancel. From v1 issue #131 lesson. */
export declare const DEFAULT_MAX_IDLE_FIRES = 3;
/**
 * Checks whether a string is a valid TriggerType.
 *
 * @param value - The string to check
 * @returns True if value is a valid TriggerType
 */
export declare function isValidTriggerType(value: string): value is TriggerType;
/**
 * Checks whether a string is a valid TriggerStatus.
 *
 * @param value - The string to check
 * @returns True if value is a valid TriggerStatus
 */
export declare function isValidTriggerStatus(value: string): value is TriggerStatus;
/**
 * Validates that a trigger config's type field matches its parent type.
 *
 * @param config - The config to validate
 * @returns True if the config is internally consistent
 */
export declare function isValidTriggerConfig(config: TriggerConfig): boolean;
/**
 * Validates that an unknown value is structurally a valid Trigger.
 *
 * @param value - Unknown value to validate
 * @returns True if value conforms to the Trigger interface
 */
export declare function isTrigger(value: unknown): value is Trigger;
/**
 * Checks whether a TriggerAction has at least one action defined.
 *
 * @param action - The action to validate
 * @returns True if at least one action field is set
 */
export declare function isValidTriggerAction(action: TriggerAction): boolean;
/**
 * Validates CreateTriggerInput and returns an array of error messages.
 *
 * @param input - The creation input to validate
 * @returns Array of validation error strings (empty = valid)
 */
export declare function validateCreateTriggerInput(input: CreateTriggerInput): string[];
/**
 * Creates a new Trigger with sensible defaults.
 *
 * @param input - Required and optional creation fields
 * @returns A fully populated Trigger object
 *
 * @example
 * ```typescript
 * const trigger = createTrigger({
 *   type: 'time',
 *   config: { type: 'time', cronExpression: '0 9 * * 1' },
 *   action: { runReconciler: true },
 *   createdBy: 'system',
 * });
 * ```
 */
export declare function createTrigger(input: CreateTriggerInput): Trigger;
//# sourceMappingURL=trigger.types.d.ts.map