"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.WireguardInterface = void 0;
var ParseResult = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/schema/ParseResult"));
var Schema = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/schema/Schema"));
var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect"));
var Function = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Function"));
var internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./internal/wireguardInterface.js"));
function _getRequireWildcardCache(e) {
  if ("function" != typeof WeakMap) return null;
  var r = new WeakMap(),
    t = new WeakMap();
  return (_getRequireWildcardCache = function (e) {
    return e ? t : r;
  })(e);
}
function _interopRequireWildcard(e, r) {
  if (!r && e && e.__esModule) return e;
  if (null === e || "object" != typeof e && "function" != typeof e) return {
    default: e
  };
  var t = _getRequireWildcardCache(r);
  if (t && t.has(e)) return t.get(e);
  var n = {
      __proto__: null
    },
    a = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
    var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
    i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
  }
  return n.default = e, t && t.set(e, n), n;
}
/**
 * @since 1.0.0
 */

/**
 * A wireguard interface name.
 *
 * @since 1.0.0
 * @category Datatypes
 */
class WireguardInterface extends Schema.Class("WireguardInterface")({
  /**
   * Ensures the interface name matches the platform's interface name regex.
   */
  Name: Schema.transformOrFail(Schema.string, Schema.string, (s, _options, ast) => Function.pipe(internal.InterfaceRegExpForPlatform, Effect.mapError(error => new ParseResult.Type(ast, s, error.message)), Effect.flatMap(x => x.test(s) ? Effect.succeed(s) : Effect.fail(new ParseResult.Type(ast, s, `Expected interface name to match ${x}`)))), s => Effect.succeed(s))
}) {
  /**
   * @since 1.0.0
   * @category Constructors
   */
  static getNextAvailableInterface = internal.getNextAvailableInterface;
  /**
   * Starts a wireguard tunnel that will be gracefully shutdown and stop serving
   * traffic once the scope is closed. If no how options is specified, then the
   * interface will be brought up using the bundled-wireguard-go+userspace-api method.
   *
   * @param config - The wireguard configuration to use in INI format.
   * @param options - Options to control how the wireguard configuration is applied.
   *
   * @since 1.0.0
   * @category Wireguard
   */
  upScoped = (config, options) => internal.upScoped(config, options)(this);
  /**
   * Starts a wireguard tunnel that will continue to run and serve traffic
   * even after the nodejs process exits. If no how options is specified, then the
   * interface will be brought up using the bundled-wireguard-go+userspace-api method.
   *
   * @param config - The wireguard configuration to use in INI format.
   * @param options - Options to control how the wireguard configuration is applied.
   *
   * @since 1.0.0
   * @category Wireguard
   */
  up = (config, options) => internal.up(config, options)(this);
  /**
   * Stops a previously started wireguard tunnel.
   *
   * @since 1.0.0
   * @category Wireguard
   */
  down = options => internal.down(this, options);
}
exports.WireguardInterface = WireguardInterface;
var _default = exports.default = WireguardInterface;
//# sourceMappingURL=WireguardInterface.js.map