import { getDiskFile } from '../../disk.js';
import { transcribeFile } from '../../transcription.js';

export async function transcribe_audio(args = {}, opts = {}) {
  const fileId = args.file_id;
  if (!fileId) throw new Error('file_id is required');
  const source = getDiskFile(fileId);
  if (!source) throw new Error('source file not found');
  const useLocal = Boolean(args.use_local || opts.use_local);
  const provider = args.provider || opts.provider;
  if (source.local_only && !useLocal) {
    return {
      ok: false,
      status: 'allowlist_violation',
      reason: 'local_only audio cannot be sent to remote providers; rerun with use_local=true',
      missing_entry: { tool_name: 'transcribe_audio', scope_key: 'audio_source', scope_value: `disk_file:${fileId}` },
    };
  }
  return transcribeFile(fileId, { ...opts, ...args, use_local: useLocal, provider });
}
