import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { backendFetch } from '$lib/server/scraper';
import type { Voice } from '$lib/types';

/**
 * GET /api/voices
 * Proxies the voice list from the backend (Kokoro + pocket-tts).
 * Returns { voices: Voice[] }
 */
export const GET: RequestHandler = async () => {
	try {
		const res = await backendFetch('/api/voices');
		if (!res.ok) {
			return json({ voices: [] });
		}
		const data = (await res.json()) as { voices: Voice[] };
		return json({ voices: data.voices ?? [] });
	} catch {
		return json({ voices: [] });
	}
};
