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

export const dynamic = 'force-dynamic';

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