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

/**
 * GET /api/admin/scrape/status
 * Admin-only proxy to the Go backend's /api/scrape/status endpoint.
 */
export const GET: RequestHandler = async ({ locals }) => {
	if (!locals.user || locals.user.role !== 'admin') {
		throw error(403, 'Forbidden');
	}
	try {
		const res = await backendFetch('/api/scrape/status');
		if (!res.ok) return json({ running: false });
		const data = await res.json();
		return json({ running: data.running ?? false });
	} catch {
		return json({ running: false });
	}
};
