import { NextResponse } from "next/server";
import { getCurrentUser } from "@/lib/auth";
import { getMemoryLog } from "@/lib/services/client-memory";

export const dynamic = "force-dynamic";

export async function GET(req: Request) {
  const user = await getCurrentUser();
  if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
  const brandId = new URL(req.url).searchParams.get("brandId");
  if (!brandId) return NextResponse.json({ error: "brandId required" }, { status: 400 });
  const limit = Math.max(1, Math.min(200, Number(new URL(req.url).searchParams.get("limit") || 50)));
  const entries = await getMemoryLog(brandId, limit);
  return NextResponse.json({ entries });
}
