"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 wrap_with_network_conditions_exports = {};
__export(wrap_with_network_conditions_exports, {
  wrapWithNetworkConditions: () => wrapWithNetworkConditions
});
module.exports = __toCommonJS(wrap_with_network_conditions_exports);
const wrapWithNetworkConditions = (fn, getDevState) => ((...args) => {
  const devState = getDevState();
  switch (devState.type) {
    case "BROKEN": {
      const { status, delay, response } = devState;
      return new Promise(
        (_resolve, reject) => setTimeout(() => reject(new MockHttpError({ status, response })), delay * 1e3)
      );
    }
    case "DELAYED": {
      const { delay } = devState;
      return Promise.all([fn(...args), new Promise((r) => setTimeout(r, delay * 1e3))]).then(
        ([result]) => result
      );
    }
    default: {
      return fn(...args);
    }
  }
});
const MOCK_REQUEST_ID = "requestIdMock";
class MockHttpError extends Error {
  constructor(props) {
    super();
    this.response = { status: props.status, requestId: MOCK_REQUEST_ID, ...props.response };
  }
}
//# sourceMappingURL=wrap-with-network-conditions.js.map
