import type { TranscriptionStatus } from './recordings'

/** Maps a transcription state to the JSON both recording routes return (same shape the modal reads). */
export const statusResponse = (file: string, status: TranscriptionStatus) => {
  if (status.state === 'done') {
    const t = status.transcript
    return { status: 200, file, cached: status.cached, language: t.language, text: t.text, segments: t.segments, createdAt: t.createdAt, audioSeconds: t.audioSeconds }
  }
  if (status.state === 'pending') return { status: 202, file, pending: true, startedAt: status.startedAt }
  if (status.state === 'failed') {
    if (status.noSpeech) return { status: 422, file, message: 'Keine Sprache erkannt oder Transkription nicht verfügbar (whisper/ffmpeg auf dem Server?)' }
    return { status: 502, file, message: status.message || 'Transcription failed' }
  }
  return { status: 404, file, message: 'Keine Transkription gestartet' }
}
