import { NextRequest, NextResponse } from "next/server";
import { getCurrentUser } from "@/lib/auth";
import { getTripAnalytics } from "@/lib/queries";

export async function GET(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
  const user = await getCurrentUser(req);
  if (!user) return NextResponse.json({ error: "Forbidden" }, { status: 403 });
  const { id } = await params;
  try {
    const analytics = await getTripAnalytics(Number(id), user.id);
    return NextResponse.json(analytics);
  } catch {
    return NextResponse.json({ error: "Not found" }, { status: 404 });
  }
}
