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 GET(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 unreadCount = await em.count(Notification, {
    recipientUserId: auth.sub,
    tenantId: auth.tenantId,
    status: "unread"
  });
  return NextResponse.json({ ok: true, unreadCount });
}
const successSchema = z.object({
  ok: z.literal(true),
  unreadCount: z.number()
});
const errorSchema = z.object({ ok: z.literal(false), error: z.string() });
const methodDoc = {
  summary: "Get unread notification count",
  description: "Returns the number of unread notifications for the authenticated customer user.",
  tags: ["Customer Portal"],
  responses: [{ status: 200, description: "Unread count", schema: successSchema }],
  errors: [{ status: 401, description: "Not authenticated", schema: errorSchema }]
};
const openApi = {
  summary: "Customer unread notification count",
  methods: { GET: methodDoc }
};
export {
  GET,
  metadata,
  openApi
};
//# sourceMappingURL=unread-count.js.map
