import { AgentEngineType } from '../../value-objects/agent-engine-type.vo';

export interface AgentEnginePort {
  readonly engineType: AgentEngineType;
  executeTask(params: EngineTaskParams): AsyncGenerator<EngineStreamEvent>;
  cancelTask(sessionId: string): Promise<void>;
  continueSession(
    sessionId: string,
    message: string,
    conversationHistory?: Array<{ role: 'user' | 'assistant'; content: string | any[] }>,
  ): AsyncGenerator<EngineStreamEvent>;
  healthCheck(): Promise<boolean>;
}

export interface EngineTaskParams {
  sessionId: string;
  prompt: string;
  systemPrompt: string;
  allowedTools: string[];
  maxTurns: number;
  maxBudgetUsd?: number;
  context?: Record<string, unknown>;
  skill?: { name: string; arguments: string };
  /** Conversation history messages to prepend for multi-turn context. */
  conversationHistory?: Array<{
    role: 'user' | 'assistant';
    content: string | any[];
  }>;
  /** SDK session ID for native resume (Agent SDK engine only). */
  resumeSessionId?: string;
}

export type EngineStreamEvent =
  | { type: 'thinking'; content: string }
  | { type: 'text'; content: string }
  | { type: 'tool_use'; toolName: string; input: Record<string, unknown> }
  | { type: 'tool_result'; toolName: string; output: string; isError: boolean }
  | { type: 'approval_required'; command: string; riskLevel: number; taskId: string }
  | {
      type: 'completed';
      summary: string;
      tokensUsed?: number;
      inputTokens?: number;
      outputTokens?: number;
      costUsd?: number;
      model?: string;
    }
  | { type: 'error'; message: string; code: string }
  | { type: 'cancelled'; message: string; code: string }
  | { type: 'task_info'; taskId: string };
