import { NextResponse } from "next/server";
import { z } from "zod";
import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
import { readCookieFromHeader } from "@open-mercato/core/modules/customer_accounts/lib/customerAuth";
const metadata = { requireAuth: false };
async function POST(req) {
  const cookieHeader = req.headers.get("cookie") || "";
  const sessionToken = readCookieFromHeader(cookieHeader, "customer_session_token");
  if (sessionToken) {
    try {
      const decodedToken = decodeURIComponent(sessionToken);
      const container = await createRequestContainer();
      const customerSessionService = container.resolve("customerSessionService");
      const session = await customerSessionService.findByToken(decodedToken);
      if (session) {
        await customerSessionService.revokeSession(session.id);
      }
    } catch {
    }
  }
  const res = NextResponse.json({ ok: true });
  res.cookies.set("customer_auth_token", "", {
    httpOnly: true,
    path: "/",
    sameSite: "lax",
    secure: process.env.NODE_ENV === "production",
    maxAge: 0
  });
  res.cookies.set("customer_session_token", "", {
    httpOnly: true,
    path: "/",
    sameSite: "lax",
    secure: process.env.NODE_ENV === "production",
    maxAge: 0
  });
  return res;
}
const successSchema = z.object({ ok: z.literal(true) });
const methodDoc = {
  summary: "Customer logout",
  description: "Revokes the current session and clears authentication cookies.",
  tags: ["Customer Portal"],
  responses: [{ status: 200, description: "Logged out", schema: successSchema }]
};
const openApi = {
  summary: "Customer logout",
  methods: { POST: methodDoc }
};
export {
  POST,
  metadata,
  openApi
};
//# sourceMappingURL=logout.js.map
