/**
 * Event types for pub/sub
 */

export type EventType =
  | "agent.spawned"
  | "agent.running"
  | "agent.completed"
  | "agent.failed"
  | "agent.killed"
  | "agent.cleanup"
  | "task.assigned"
  | "task.queued"
  | "task.processing"
  | "task.retry"
  | "task.executing"
  | "task.completed"
  | "task.failed";

export interface BaseEvent {
  type: EventType;
  timestamp: string;
}

export interface AgentEvent extends BaseEvent {
  type:
    | "agent.spawned"
    | "agent.running"
    | "agent.completed"
    | "agent.failed"
    | "agent.killed"
    | "agent.cleanup";
  agentId: string;
  taskId: string;
  error?: string;
  cleanup?: {
    docker: boolean;
    worktree: boolean;
    state: boolean;
  };
}

export interface TaskEvent extends BaseEvent {
  type:
    | "task.assigned"
    | "task.queued"
    | "task.processing"
    | "task.retry"
    | "task.executing"
    | "task.completed"
    | "task.failed";
  taskId?: string;
  agentId?: string;
  error?: string;
  data?: Record<string, unknown>;
}

export type OrchestratorEvent = AgentEvent | TaskEvent;

/**
 * Event handler type
 */
export type EventHandler = (event: OrchestratorEvent) => void | Promise<void>;
