import { NextResponse } from "next/server";
import { z } from "zod";
import { getCustomerAuthFromRequest } from "@open-mercato/core/modules/customer_accounts/lib/customerAuth";
import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
import { Notification } from "@open-mercato/core/modules/notifications/data/entities";
const metadata = { requireAuth: false };
async function PUT(req, { params }) {
  const auth = await getCustomerAuthFromRequest(req);
  if (!auth) {
    return NextResponse.json({ ok: false, error: "Authentication required" }, { status: 401 });
  }
  const container = await createRequestContainer();
  const em = container.resolve("em");
  const notification = await em.findOne(Notification, {
    id: params.id,
    recipientUserId: auth.sub,
    tenantId: auth.tenantId
  });
  if (!notification) {
    return NextResponse.json({ ok: false, error: "Notification not found" }, { status: 404 });
  }
  notification.status = "dismissed";
  notification.dismissedAt = /* @__PURE__ */ new Date();
  await em.flush();
  return NextResponse.json({ ok: true });
}
const successSchema = z.object({ ok: z.literal(true) });
const errorSchema = z.object({ ok: z.literal(false), error: z.string() });
const methodDoc = {
  summary: "Dismiss notification",
  description: "Dismisses a single notification for the authenticated customer user.",
  tags: ["Customer Portal"],
  responses: [{ status: 200, description: "Notification dismissed", schema: successSchema }],
  errors: [
    { status: 401, description: "Not authenticated", schema: errorSchema },
    { status: 404, description: "Notification not found", schema: errorSchema }
  ]
};
const openApi = {
  summary: "Dismiss customer notification",
  pathParams: z.object({ id: z.string().uuid() }),
  methods: { PUT: methodDoc }
};
export {
  PUT,
  metadata,
  openApi
};
//# sourceMappingURL=dismiss.js.map
