// ── Extraction types (shared across consumers) ─────────────────

export interface ExtractionEntity {
  extraction_class: string;
  extraction_text: string;
  attributes?: Record<string, string>;
  start_offset?: number;
  end_offset?: number;
}

export interface ExtractionExample {
  text: string;
  extractions: ExtractionEntity[];
}

export interface ExtractionTask {
  id: string;
  name: string;
  description?: string;
  prompt: string;
  classes: string[];
  examples?: ExtractionExample[];
  defaultModelId?: string;
  builtIn: boolean;
  productId: string;
  createdAt?: string;
  updatedAt?: string;
}

// ── Request / Response types ────────────────────────────────────

export interface ExtractRequest {
  text: string;
  taskId?: string;
  taskPrompt?: string;
  examples?: ExtractionExample[];
  modelId?: string;
  options?: {
    extractionPasses?: number;
    maxWorkers?: number;
    maxCharBuffer?: number;
  };
  productId?: string;
}

export interface ExtractResponse {
  extractions: ExtractionEntity[];
  metadata: {
    modelId: string;
    durationMs: number;
    tokenCount?: number;
    charCount: number;
  };
  requestId?: string;
}

export interface BatchExtractRequest {
  inputs: Array<{
    text: string;
    taskId?: string;
    taskPrompt?: string;
  }>;
  examples?: ExtractionExample[];
  modelId?: string;
  productId?: string;
}

export interface BatchExtractResponse {
  results: ExtractResponse[];
  requestId?: string;
}

// ── Transcription types ─────────────────────────────────────────

export interface TranscribeRequest {
  /** URL of the audio file (e.g. Azure Blob SAS URL). */
  audioUrl: string;
  /** Override the Whisper model (default: whisper-1). */
  model?: string;
  /** ISO 639-1 language hint (e.g. 'en', 'es'). Improves accuracy. */
  language?: string;
  /** Optional prompt to guide the transcription style. */
  prompt?: string;
  /** Response format: 'text' | 'json' | 'verbose_json'. */
  responseFormat?: 'text' | 'json' | 'verbose_json';
  /** Product ID for scoping / rate limiting. */
  productId?: string;
}

export interface TranscribeResponse {
  /** The transcribed text. */
  text: string;
  /** Detected or specified language code. */
  language: string | null;
  /** Duration of the audio in seconds (when available). */
  durationSeconds: number | null;
  /** Whisper model used. */
  model: string;
  /** Processing time in milliseconds. */
  durationMs: number;
  /** Request ID for tracing. */
  requestId?: string;
}

// ── Client config ───────────────────────────────────────────────

export interface ExtractionClientConfig {
  baseUrl: string;
  getToken?: () => string | null;
}
