/**
 * Onboarding Dismissal API
 * POST: Dismiss onboarding banner (user can still access onboarding page)
 */

import { NextRequest, NextResponse } from "next/server";
import { auth } from "@/lib/auth";
import { prisma as db } from "@/lib/db";

// POST /api/onboarding/dismiss - Dismiss onboarding banner
export async function POST(req: NextRequest) {
  try {
    const session = await auth();

    if (!session?.user?.id) {
      return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
    }

    const now = new Date();

    // Dismiss onboarding banner
    const progress = await db.onboarding_progress.update({
      where: { userId: session.user.id },
      data: {
        dismissedAt: now,
      },
    });

    return NextResponse.json({
      success: true,
      progress,
    });
  } catch (error) {
    console.error("Error dismissing onboarding:", error);
    return NextResponse.json(
      { error: "Internal server error" },
      { status: 500 },
    );
  }
}
