"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var utils_exports = {};
__export(utils_exports, {
  BASE_LOG_OBJECT: () => BASE_LOG_OBJECT,
  CORRELATION_ID: () => CORRELATION_ID,
  LOGGER_OPTIONS: () => LOGGER_OPTIONS,
  getLogger: () => getLogger,
  waitForLoggingRequest: () => waitForLoggingRequest,
  waitForRequest: () => waitForRequest
});
module.exports = __toCommonJS(utils_exports);
var import_msw = require("msw");
var import_server = require("./server.js");
var import_types = require("../types.js");
var import__ = require("../index.js");
var import_browserDetails = require("../browserDetails.js");
const HTTP_TRANSPORT = (0, import__.http)(import_server.LOGGING_V2_API);
const CORRELATION_ID = "123456789";
jest.mock("uuid", () => ({ v4: () => "123456789" }));
const LOGGER_OPTIONS = {
  index: "pui",
  environment: import_types.Environment.QA,
  team: "ui-platform",
  appName: "pui-diagnostics",
  appVersion: "1.0.0"
};
const BASE_LOG_OBJECT = {
  host: "NA",
  environment: import_types.Environment.DEV,
  appVersion: "",
  location: "NA",
  instanceId: "",
  customerId: "",
  userId: "",
  correlationId: CORRELATION_ID,
  context: import_browserDetails.browserDetails
};
const waitForRequest = (method, url) => {
  let requestId = "";
  return new Promise((resolve, reject) => {
    import_server.server.events.on("request:start", (req) => {
      const matchesMethod = req.method.toLowerCase() === method.toLowerCase();
      const matchesUrl = (0, import_msw.matchRequestUrl)(req.url, url).matches;
      if (matchesMethod && matchesUrl) {
        requestId = req.id;
      }
    });
    import_server.server.events.on("request:match", (req) => {
      if (req.id === requestId) {
        resolve(req);
        requestId = "";
      }
    });
    import_server.server.events.on("request:unhandled", (req) => {
      if (req.id === requestId) {
        reject(
          new Error(`The ${req.method} ${req.url.href} request was unhandled.`)
        );
        requestId = "";
      }
    });
  });
};
const waitForLoggingRequest = () => waitForRequest("POST", import_server.LOGGING_V2_API);
const getLogger = (options = {}) => (0, import__.logger)({ ...LOGGER_OPTIONS, transport: HTTP_TRANSPORT, ...options });
