import { NextResponse } from "next/server";
import { runWithCacheTenant } from "@open-mercato/cache";
import { rejectProposal } from "../../../../lib/executionEngine.js";
import { resolveCache, invalidateCountsCache } from "../../../../lib/cache.js";
import {
  resolveRequestContext,
  resolveProposal,
  toExecutionContext,
  handleRouteError,
  isErrorResponse
} from "../../../routeHelpers.js";
const metadata = {
  POST: { requireAuth: true, requireFeatures: ["inbox_ops.proposals.manage"] }
};
async function POST(req) {
  try {
    const ctx = await resolveRequestContext(req);
    const proposal = await resolveProposal(new URL(req.url), ctx);
    if (isErrorResponse(proposal)) return proposal;
    await rejectProposal(proposal.id, toExecutionContext(ctx));
    const cache = resolveCache(ctx.container);
    await runWithCacheTenant(ctx.tenantId, () => invalidateCountsCache(cache, ctx.tenantId));
    return NextResponse.json({ ok: true });
  } catch (err) {
    return handleRouteError(err, "reject proposal");
  }
}
const openApi = {
  tag: "InboxOps",
  summary: "Reject proposal",
  methods: {
    POST: {
      summary: "Reject entire proposal (all pending actions)",
      responses: [
        { status: 200, description: "Proposal rejected" },
        { status: 404, description: "Proposal not found" }
      ]
    }
  }
};
export {
  POST,
  metadata,
  openApi
};
//# sourceMappingURL=route.js.map
