/**
 * Shared LLM Transport Interface
 *
 * This is the hexagonal port that both Oracle and OPR use to talk to LLMs.
 * Having a single transport means:
 * - No duplicate adapter code
 * - Shared rate limiting, caching, etc.
 * - Unified cost tracking
 */

/**
 * A message in the conversation
 */
export interface LLMMessage {
  role: 'system' | 'user' | 'assistant';
  content: string;
}

/**
 * Request to the LLM
 */
export interface LLMRequest {
  messages: LLMMessage[];
  model?: string;
  temperature?: number;
  maxTokens?: number;
  /** Optional metadata for tracking/logging */
  metadata?: {
    kernelId?: string;
    op?: string;
    attempt?: number;
    requestId?: string;
  };
}

/**
 * Usage information from LLM response
 */
export interface LLMUsage {
  promptTokens: number;
  completionTokens: number;
  totalTokens: number;
  estimatedCost: number;
}

/**
 * Response from the LLM
 */
export interface LLMResponse {
  text: string;
  usage?: LLMUsage;
  model?: string;
  finishReason?: 'stop' | 'length' | 'content_filter' | string;
}

/**
 * The transport interface - both Oracle and OPR adapters implement this
 */
export interface LLMTransport {
  /** Send a completion request */
  complete(request: LLMRequest): Promise<LLMResponse>;

  /** Get the default model name */
  getModel(): string;

  /** Optional: get last usage stats */
  getLastUsage?(): LLMUsage | undefined;
}

/**
 * Configuration for creating transports
 */
// Vendor-specific transport configs removed in JOB-06.
// Use @omega/driver-* packages via DriverRegistry instead.

/**
 * Cost estimation helpers (rough per-token pricing, model-specific)
 */
const MODEL_COSTS: Record<string, { input: number; output: number }> = {
  'default': { input: 0.001, output: 0.002 },
};

export function estimateCost(
  usage: { promptTokens: number; completionTokens: number },
  model: string
): number {
  const costs = MODEL_COSTS[model] ?? { input: 0.001, output: 0.002 };
  return (usage.promptTokens * costs.input + usage.completionTokens * costs.output) / 1000;
}
