/**
 * Shared types for AI client operations.
 */

/** Token usage information from AI providers. */
export interface TokenUsage {
  promptTokens: number;
  completionTokens: number;
  totalTokens?: number;
}

/** Base response metadata from any AI operation. */
export interface AIResponseMeta {
  provider: string;
  model?: string;
  latencyMs: number;
}

/** Error from AI operations. */
export interface AIError extends Error {
  code: string;
  provider?: string;
  retryable: boolean;
}

/** Create a typed AI error. */
export function createAIError(
  message: string,
  code: string,
  provider?: string,
  retryable = false
): AIError {
  const error = new Error(message) as AIError;
  error.code = code;
  error.provider = provider;
  error.retryable = retryable;
  return error;
}

/** Common error codes. */
export const ErrorCodes = {
  NETWORK_ERROR: 'NETWORK_ERROR',
  TIMEOUT: 'TIMEOUT',
  RATE_LIMITED: 'RATE_LIMITED',
  INVALID_REQUEST: 'INVALID_REQUEST',
  PROVIDER_ERROR: 'PROVIDER_ERROR',
  QUOTA_EXCEEDED: 'QUOTA_EXCEEDED',
  CONTENT_FILTERED: 'CONTENT_FILTERED',
} as const;

export type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
