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) {
  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 now = /* @__PURE__ */ new Date();
  const count = await em.nativeUpdate(Notification, {
    recipientUserId: auth.sub,
    tenantId: auth.tenantId,
    status: "unread"
  }, {
    status: "read",
    readAt: now
  });
  return NextResponse.json({ ok: true, count });
}
const successSchema = z.object({
  ok: z.literal(true),
  count: z.number()
});
const errorSchema = z.object({ ok: z.literal(false), error: z.string() });
const methodDoc = {
  summary: "Mark all notifications as read",
  description: "Marks all unread notifications as read for the authenticated customer user.",
  tags: ["Customer Portal"],
  responses: [{ status: 200, description: "All notifications marked as read", schema: successSchema }],
  errors: [{ status: 401, description: "Not authenticated", schema: errorSchema }]
};
const openApi = {
  summary: "Mark all customer notifications as read",
  methods: { PUT: methodDoc }
};
export {
  PUT,
  metadata,
  openApi
};
//# sourceMappingURL=mark-all-read.js.map
