import type {NextRequest} from 'next/server';
import {ok, parseQuery, requireApiSession, simulate, wantsEmpty} from '@/shared/services/apiRoute';
import {buildStores} from '@/features/stores/mock/stores.mock';

export const dynamic = 'force-dynamic';

export async function GET(req: NextRequest) {
  const denied = await requireApiSession();
  if (denied) return denied;
  const q = parseQuery(req);
  const simulated = await simulate(q);
  if (simulated) return simulated;
  return ok(wantsEmpty(q) ? [] : buildStores(q.range, q.nowMs), q);
}
