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 VoiceConfigView = VoiceConfig & {
  apiKeyConfigured: boolean
  apiKeyEnv: string
}

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 type VoiceCommand =
  | "send"
  | "run"
  | "accept"
  | "reject"
  | "clear"
  | "stop"
  | "scroll-up"
  | "scroll-down"
  | "focus"
  | "newline"

export type VoiceParseResult =
  | { type: "command"; command: VoiceCommand; raw: string }
  | { type: "text"; text: string }

export type VoicePlatformAPI = {
  getConfig: () => Promise<VoiceConfigView>
  setConfig: (config: Partial<VoiceConfig>) => Promise<VoiceConfigView>
  start: () => Promise<RecordingState>
  stop: () => Promise<RecordingState>
  toggle: () => Promise<RecordingState>
  getState: () => Promise<RecordingState>
  sendAudioChunk: (chunk: ArrayBuffer) => Promise<void>
  checkApiKey: (provider?: VoiceProvider) => Promise<{ provider: VoiceProvider; configured: boolean; env: string }>
  onTranscription: (cb: (result: TranscriptionResult) => void) => () => void
  onRecordingState: (cb: (state: RecordingState) => void) => () => void
  onError: (cb: (error: VoiceError) => void) => () => void
  onCaptureMode: (cb: (mode: "native" | "renderer") => void) => () => void
}

export type VoiceActions = {
  insertText: (text: string) => void
  submit: () => void
  clear: () => void
  stop: () => void
  accept: () => void
  reject: () => void
  scrollUp: () => void
  scrollDown: () => void
  focus: () => void
  newline: () => void
  run: () => void
}
