var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
  ErrorCode2["PaymentCreationFailure"] = "payment_not_created_error";
  ErrorCode2["NoAvailableUsersFound"] = "no_available_users_found_error";
  ErrorCode2["ChargeCardFailure"] = "couldnt_charge_card_error";
  ErrorCode2["RequestBodyWithouEnd"] = "request_body_end_time_internal_error";
  ErrorCode2["AlreadySignedUpForBooking"] = "already_signed_up_for_this_booking_error";
  ErrorCode2["FixedHostsUnavailableForBooking"] = "fixed_hosts_unavailable_for_booking";
  ErrorCode2["RoundRobinHostsUnavailableForBooking"] = "round_robin_hosts_unavailable_for_booking";
  ErrorCode2["EventTypeNotFound"] = "event_type_not_found_error";
  ErrorCode2["BookingNotFound"] = "booking_not_found_error";
  ErrorCode2["BookingSeatsFull"] = "booking_seats_full_error";
  ErrorCode2["MissingPaymentCredential"] = "missing_payment_credential_error";
  ErrorCode2["MissingPaymentAppId"] = "missing_payment_app_id_error";
  ErrorCode2["NotEnoughAvailableSeats"] = "not_enough_available_seats_error";
  ErrorCode2["AvailabilityNotFoundInSchedule"] = "availability_not_found_in_schedule_error";
  ErrorCode2["CancelledBookingsCannotBeRescheduled"] = "cancelled_bookings_cannot_be_rescheduled";
  ErrorCode2["UnableToSubscribeToThePlatform"] = "unable_to_subscribe_to_the_platform";
  ErrorCode2["UpdatingOauthClientError"] = "updating_oauth_client_error";
  ErrorCode2["CreatingOauthClientError"] = "creating_oauth_client_error";
  ErrorCode2["BookingTimeOutOfBounds"] = "booking_time_out_of_bounds_error";
  ErrorCode2["BookingConflict"] = "booking_conflict_error";
  ErrorCode2["BookerLimitExceeded"] = "booker_limit_exceeded_error";
  ErrorCode2["BookerLimitExceededReschedule"] = "booker_limit_exceeded_error_reschedule";
  ErrorCode2["BookingNotAllowedByRestrictionSchedule"] = "booking_not_allowed_by_restriction_schedule_error";
  ErrorCode2["RestrictionScheduleNotFound"] = "restriction_schedule_not_found_error";
  ErrorCode2["EventTypeNoHosts"] = "event_type_no_hosts";
  ErrorCode2["RequestBodyInvalid"] = "request_body_invalid_error";
  ErrorCode2["PrivateLinkExpired"] = "private_link_expired";
  return ErrorCode2;
})(ErrorCode || {});
class ErrorWithCode extends Error {
  constructor(code, message, data) {
    super(message);
    this.code = code;
    this.data = data;
  }
  static get Factory() {
    return new Proxy(ErrorWithCode, {
      get(_, prop) {
        if (prop in ErrorCode) {
          const code = ErrorCode[prop];
          return (message, data) => new ErrorWithCode(code, message, data);
        }
        throw new Error(`Unknown error code: ${prop}`);
      }
    });
  }
}
function getErrorFromUnknown(cause) {
  if (cause instanceof Error) {
    return cause;
  }
  if (typeof cause === "string") {
    return new Error(cause, { cause });
  }
  return new Error(`Unhandled error of type '${typeof cause}''`);
}
async function handleErrorsJson(response) {
  if (response.headers.get("content-encoding") === "gzip") {
    const responseText = await response.text();
    return new Promise((resolve) => resolve(JSON.parse(responseText)));
  }
  if (response.status === 204) {
    return new Promise((resolve) => resolve({}));
  }
  if (!response.ok && (response.status < 200 || response.status >= 300)) {
    response.json().then(console.log);
    throw Error(response.statusText);
  }
  return response.json();
}
function handleErrorsRaw(response) {
  if (response.status === 204) {
    console.error({ response });
    return "{}";
  }
  if (!response.ok || response.status < 200 || response.status >= 300) {
    response.text().then(console.log);
    throw Error(response.statusText);
  }
  return response.text();
}
export {
  ErrorWithCode as E,
  ErrorCode as a,
  handleErrorsRaw as b,
  getErrorFromUnknown as g,
  handleErrorsJson as h
};
