/**
 * INPUT 積木 - 觸發器介面
 * 用途: Webhook, Cron, Alert, Email 等觸發來源
 */

import type { LeWOOOgoPlugin, Unsubscribe } from './plugin'

/**
 * 觸發事件的上下文
 */
export interface TriggerContext {
  triggerId: string
  timestamp: Date
  source: string
  metadata?: Record<string, unknown>
}

/**
 * 觸發事件
 */
export interface TriggerEvent<T = unknown> {
  context: TriggerContext
  payload: T
}

/**
 * 觸發處理器
 */
export type TriggerHandler<T = unknown> = (event: TriggerEvent<T>) => Promise<void>

/**
 * 觸發器 Schema
 */
export interface TriggerSchema {
  payloadType: string
  description?: string
  example?: unknown
}

/**
 * INPUT 觸發器 Plugin
 */
export interface TriggerPlugin<T = unknown> extends LeWOOOgoPlugin {
  category: 'INPUT'

  /**
   * 訂閱觸發事件
   */
  subscribe(handler: TriggerHandler<T>): Unsubscribe

  /**
   * 取得觸發器 Schema
   */
  getSchema(): TriggerSchema
}
