import { buildDashboardSummary } from '../selectors/summary-selector.js';
export const handleSummaryRoutes = async (ctx, req, res, url) => {
    if (req.method === 'GET' && url.pathname === '/api/dashboard/summary') {
        const runtimeId = url.searchParams.get('runtimeId') || 'default';
        await ctx.respondCachedJson(res, `dashboard-summary:${runtimeId}`, 5_000, () => buildDashboardSummary(ctx, url));
        return true;
    }
    if (req.method === 'GET' && url.pathname === '/api/dashboard/entity') {
        const kind = url.searchParams.get('kind') ?? '';
        const id = url.searchParams.get('id') ?? '';
        if (!kind || !id) {
            ctx.respondJson(res, { error: 'kind-and-id-required' }, 400);
            return true;
        }
        const entity = ctx.resolveDashboardEntity(kind, id, url);
        ctx.respondJson(res, entity ?? { error: 'dashboard-entity-not-found', kind, id }, entity ? 200 : 404);
        return true;
    }
    return false;
};
