import { expect } from "@playwright/test";
import { apiRequest } from "./api.js";
import { expectId, readJsonSafe } from "./generalFixtures.js";
const TEST_SEED_PATH = "/api/communication_channels/test-seed";
async function isChannelSeedingAvailable(request, token) {
  const response = await apiRequest(request, "POST", TEST_SEED_PATH, {
    token,
    data: { action: "__probe__" }
  });
  return response.status() !== 404;
}
async function seedConnectedChannel(request, token, input = {}) {
  const response = await apiRequest(request, "POST", TEST_SEED_PATH, {
    token,
    data: { action: "connect-channel", ...input }
  });
  expect(
    response.status(),
    "POST /api/communication_channels/test-seed (connect-channel) should return 201"
  ).toBe(201);
  const body = await readJsonSafe(response);
  return expectId(body?.channelId, "connect-channel response should include channelId");
}
async function seedInboundMessage(request, token, input) {
  const response = await apiRequest(request, "POST", TEST_SEED_PATH, {
    token,
    data: { action: "emit-inbound", ...input }
  });
  expect(
    response.status(),
    "POST /api/communication_channels/test-seed (emit-inbound) should return 201"
  ).toBe(201);
  const body = await readJsonSafe(response);
  return {
    channelLinkId: expectId(body?.channelLinkId, "emit-inbound response should include channelLinkId"),
    messageId: expectId(body?.messageId, "emit-inbound response should include messageId"),
    conversationId: expectId(
      body?.conversationId,
      "emit-inbound response should include conversationId"
    )
  };
}
async function deleteChannelIfExists(request, token, channelId) {
  if (!token || !channelId) return;
  await apiRequest(
    request,
    "DELETE",
    `/api/communication_channels/channels/${encodeURIComponent(channelId)}`,
    { token }
  ).catch(() => void 0);
}
export {
  deleteChannelIfExists,
  isChannelSeedingAvailable,
  seedConnectedChannel,
  seedInboundMessage
};
//# sourceMappingURL=communicationChannelsFixtures.js.map
