"use strict";
/* Socket Lib - Built with esbuild */
"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 options_exports = {};
__export(options_exports, {
  normalizeIterationOptions: () => normalizeIterationOptions,
  normalizeRetryOptions: () => normalizeRetryOptions,
  resolveRetryOptions: () => resolveRetryOptions
});
module.exports = __toCommonJS(options_exports);
var import_math = require("../primordials/math");
var import_internal = require("./_internal");
// @__NO_SIDE_EFFECTS__
function normalizeIterationOptions(options) {
  const opts = typeof options === "number" ? { concurrency: options } : options;
  const {
    // The number of concurrent executions performed at one time.
    concurrency = 1,
    // Retries as a number or options object.
    retries,
    // AbortSignal used to support cancellation.
    signal = import_internal.abortSignal
  } = { __proto__: null, ...opts };
  const normalizedConcurrency = (0, import_math.MathMax)(1, concurrency);
  const retryOpts = /* @__PURE__ */ resolveRetryOptions(retries);
  return {
    __proto__: null,
    concurrency: normalizedConcurrency,
    retries: /* @__PURE__ */ normalizeRetryOptions({ signal, ...retryOpts }),
    signal
  };
}
// @__NO_SIDE_EFFECTS__
function normalizeRetryOptions(options) {
  const resolved = /* @__PURE__ */ resolveRetryOptions(options);
  const {
    // Arguments to pass to the callback function.
    args = [],
    // Multiplier for exponential backoff (e.g., 2 doubles delay each retry).
    backoffFactor = 2,
    // Initial delay before the first retry (in milliseconds).
    baseDelayMs = 200,
    // Whether to apply randomness to spread out retries.
    jitter = true,
    // Upper limit for any backoff delay (in milliseconds).
    maxDelayMs = 1e4,
    // Optional callback invoked on each retry attempt:
    // (attempt: number, error: unknown, delay: number) => void
    onRetry,
    // Whether onRetry can cancel retries by returning `false`.
    onRetryCancelOnFalse = false,
    // Whether onRetry will rethrow errors.
    onRetryRethrow = false,
    // Number of retry attempts (0 = no retries, only initial attempt).
    retries = 0,
    // AbortSignal used to support cancellation.
    signal = import_internal.abortSignal
  } = resolved;
  return {
    args,
    backoffFactor,
    baseDelayMs,
    jitter,
    maxDelayMs,
    onRetry,
    onRetryCancelOnFalse,
    onRetryRethrow,
    retries,
    signal
  };
}
// @__NO_SIDE_EFFECTS__
function resolveRetryOptions(options) {
  const defaults = {
    __proto__: null,
    retries: 0,
    baseDelayMs: 200,
    maxDelayMs: 1e4,
    backoffFactor: 2
  };
  if (typeof options === "number") {
    return { ...defaults, retries: options };
  }
  return options ? { ...defaults, ...options } : defaults;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  normalizeIterationOptions,
  normalizeRetryOptions,
  resolveRetryOptions
});
