import { json, error } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { listTranslationJobs } from '$lib/server/pocketbase';

/**
 * GET /api/admin/translation-jobs
 * Returns the current translation jobs list (served from 30 s Valkey cache).
 * Used by the admin translation page for lightweight polling instead of invalidateAll().
 */
export const GET: RequestHandler = async ({ locals }) => {
	if (!locals.user || locals.user.role !== 'admin') {
		throw error(403, 'Forbidden');
	}
	const jobs = await listTranslationJobs().catch(() => []);
	return json({ jobs });
};
