import { NextResponse } from "next/server";

import { requireApiAccess } from "../../../../../lib/api/auth";
import { getRepositoryFromRuntime } from "../../../../../lib/db/repository";

interface RouteContext {
  params: Promise<{ caseId: string }>;
}

export async function POST(request: Request, context: RouteContext) {
  const access = requireApiAccess(request);
  if (!access.ok) {
    return access.response;
  }

  const { caseId } = await context.params;
  const repository = getRepositoryFromRuntime();
  const optimizationCase = await repository.archiveOptimizationCase(caseId);
  if (!optimizationCase) {
    return NextResponse.json({ error: "Case not found" }, { status: 404 });
  }

  return NextResponse.json({ case: optimizationCase });
}
