// contracts §5 — Runtime Event Contracts

import type { ISOTimeString, UUID, SessionID, ProjectID, TaskID, AgentID, ToolRunID, CommandRunID } from './ids.js'
import type { AgentType } from './runtime.js'

// EntityType and EntityRef (contracts §4)
export type EntityType =
  | "session"
  | "message"
  | "task"
  | "agent"
  | "tool_run"
  | "command_run"
  | "artifact"
  | "diagnostic"
  | "workspace"
  | "summary"
  | "capability"
  | "provider"

export interface EntityRef {
  type: EntityType
  id: string
}

// EventSource (contracts §5)
export interface EventSource {
  kind: "main" | "architecture_designer" | "scheduler" | "agent" | "tool" | "system"
  id?: string
  agent_type?: AgentType
}

// RuntimeEvent (contracts §5)
export interface RuntimeEvent<TPayload = unknown> {
  id: UUID
  type: string
  version: number
  timestamp: ISOTimeString
  session_id: SessionID
  project_id?: ProjectID
  source: EventSource
  route: string[]
  payload: TPayload
}

// EventFilter (contracts §5)
export interface EventFilter {
  session_id?: SessionID
  types?: string[]
  task_id?: TaskID
  agent_id?: AgentID
  tool_run_id?: ToolRunID
  command_run_id?: CommandRunID
  route_prefix?: string[]
  since?: ISOTimeString
}