export type VoiceProvider = "deepgram" | "groq" | "openai-whisper"

export type RecordingState = "idle" | "recording" | "processing"

export type VoiceConfig = {
  enabled: boolean
  provider: VoiceProvider
  language: string
  hotkey: string
  commands: boolean
  autoSend: boolean
}

export type TranscriptionResult = {
  text: string
  isFinal: boolean
  confidence?: number
}

export type VoiceError = {
  code: "no-api-key" | "no-microphone" | "no-recorder" | "stt-failed" | "permission-denied" | "unknown"
  message: string
}

export const DEFAULT_VOICE_CONFIG: VoiceConfig = {
  enabled: true,
  provider: "deepgram",
  language: "en",
  hotkey: "Alt+Space",
  commands: true,
  autoSend: false,
}

export function resolveApiKey(provider: VoiceProvider): string | undefined {
  if (provider === "deepgram") return process.env.DEEPGRAM_API_KEY || process.env.OPENCODE_VOICE_DEEPGRAM_API_KEY
  if (provider === "groq") return process.env.GROQ_API_KEY || process.env.OPENCODE_VOICE_GROQ_API_KEY
  return process.env.OPENAI_API_KEY || process.env.OPENCODE_VOICE_OPENAI_API_KEY
}

export function apiKeyEnvName(provider: VoiceProvider) {
  if (provider === "deepgram") return "DEEPGRAM_API_KEY"
  if (provider === "groq") return "GROQ_API_KEY"
  return "OPENAI_API_KEY"
}
