import { NextResponse } from "next/server";
import { runWithCacheTenant } from "@open-mercato/cache";
import { rejectAction } from "../../../../../../lib/executionEngine.js";
import { resolveCache, invalidateCountsCache } from "../../../../../../lib/cache.js";
import {
  resolveRequestContext,
  resolveActionAndProposal,
  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 resolved = await resolveActionAndProposal(new URL(req.url), ctx);
    if (isErrorResponse(resolved)) return resolved;
    if (resolved.action.status !== "pending" && resolved.action.status !== "failed") {
      return NextResponse.json({ error: "Action already processed" }, { status: 409 });
    }
    await rejectAction(resolved.action, 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 action");
  }
}
const openApi = {
  tag: "InboxOps",
  summary: "Reject action",
  methods: {
    POST: {
      summary: "Reject a proposal action",
      responses: [
        { status: 200, description: "Action rejected" },
        { status: 404, description: "Action not found" },
        { status: 409, description: "Action already processed" }
      ]
    }
  }
};
export {
  POST,
  metadata,
  openApi
};
//# sourceMappingURL=route.js.map
