import { prisma } from '../prisma.js';

export async function transcribeVoiceExperience(experienceId: string) {
  const experience = await prisma.voiceExperience.findUnique({
    where: { id: experienceId },
  });

  if (!experience) {
    throw new Error(`Voice experience ${experienceId} was not found.`);
  }

  await prisma.voiceExperience.update({
    where: { id: experienceId },
    data: { status: 'TRANSCRIBING' },
  });

  const transcript = await transcribeAudioObject(experience.audioObjectKey);

  await prisma.voiceExperience.update({
    where: { id: experienceId },
    data: {
      transcript,
      status: 'TRANSCRIBED',
    },
  });

  return { transcript };
}

async function transcribeAudioObject(audioObjectKey: string): Promise<string> {
  // TODO: replace this adapter with the production speech-to-text provider.
  return `Transcription placeholder for ${audioObjectKey}`;
}
