import type {NextRequest} from 'next/server';
import {ok, parseQuery, simulate, wantsEmpty} from '@/lib/api/server';
import {buildBriefing} from '@/lib/mock/briefing';

export const dynamic = 'force-dynamic';

const EMPTY = {summary: '', alerts: [], tasks: []};

export async function GET(req: NextRequest) {
  const q = parseQuery(req);
  const simulated = await simulate(q);
  if (simulated) return simulated;
  return ok(
    wantsEmpty(q) ? EMPTY : buildBriefing(q.storeId, q.range, q.nowMs),
    q,
  );
}
