import { expect } from "@playwright/test";
import { apiRequest } from "./api.js";
import { expectId, readJsonSafe } from "./generalFixtures.js";
async function createNotificationFixture(request, token, data) {
  const response = await apiRequest(request, "POST", "/api/notifications", { token, data });
  const body = await readJsonSafe(response);
  expect(response.status(), "POST /api/notifications should return 201").toBe(201);
  return expectId(body?.id, "Notification creation response should include id");
}
async function listNotifications(request, token, query) {
  const params = new URLSearchParams();
  for (const [key, value] of Object.entries(query ?? {})) {
    if (value === void 0) continue;
    params.set(key, String(value));
  }
  const path = `/api/notifications${params.toString() ? `?${params.toString()}` : ""}`;
  const response = await apiRequest(request, "GET", path, { token });
  const body = await readJsonSafe(response);
  expect(response.ok(), `GET ${path} should succeed`).toBeTruthy();
  return {
    items: body?.items ?? [],
    total: body?.total ?? 0
  };
}
async function dismissNotificationIfExists(request, token, notificationId) {
  if (!token || !notificationId) return;
  await apiRequest(
    request,
    "PUT",
    `/api/notifications/${encodeURIComponent(notificationId)}/dismiss`,
    { token }
  ).catch(() => void 0);
}
async function dismissNotificationsByType(request, token, type) {
  if (!token || !type) return;
  const notifications = await listNotifications(request, token, { type, pageSize: 100 }).catch(() => null);
  if (!notifications) return;
  await Promise.all(
    notifications.items.map((item) => typeof item.id === "string" ? item.id : null).filter((id) => Boolean(id)).map((id) => dismissNotificationIfExists(request, token, id))
  );
}
export {
  createNotificationFixture,
  dismissNotificationIfExists,
  dismissNotificationsByType,
  listNotifications
};
//# sourceMappingURL=notificationsFixtures.js.map
