"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _TargetHealth = _interopRequireDefault(require("./TargetHealth"));
var _ValidationScopes = _interopRequireDefault(require("../../../validation/ValidationScopes"));
var _ValidationUtils = _interopRequireDefault(require("../../../../utils/ValidationUtils"));
var _ValidationError = _interopRequireDefault(require("../../../validation/ValidationError"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); } /*
 * Nutanix Networking APIs
 *
 * OpenAPI spec version: 4.0.1
 *
 * NOTE: This class is auto generated by the Open API Dev Platform.
 *
 * Open API Dev Platform Codegen version: 16.9.0.8546-RELEASE
 *
 * Do not edit the class manually.
 *
 */
/**
 * The NicTarget model module.
 * @module Ntnx/NicTarget
 * @version 4.0.1
 * @class NicTarget
 */
var _NicTarget_brand = /*#__PURE__*/new WeakSet();
var NicTarget = exports["default"] = /*#__PURE__*/function () {
  /**
   * Constructs a new <code>NicTarget</code>.
   * Targets that are associated with the load balancer using virtual NIC.
   * @alias module:Ntnx/NicTarget
  */
  function NicTarget() {
    _classCallCheck(this, NicTarget);
    /*
    * toJson method for a map type which supports map with primitive keys and values of object types
    * @param {Object} obj
    * @returns {Object|Map} Returns a new transofrmed Map by calling toJson on the values if applicable.
    * Otherwise, just returns the input object.
    */
    _classPrivateMethodInitSpec(this, _NicTarget_brand);
    this.$objectType = "networking.v4.config.NicTarget";
    /** @type {object<string, any>} */
    this.$reserved = {
      '$fv': "v4.r0"
    };
    /** @type {object<string, any>} */
    this.$unknownFields = {};
  }

  /**
   * Constructs a <code>NicTarget</code> from a plain JavaScript object, optionally creating a new instance.
   * Copies all relevant properties from <code>data</code> to <code>obj</code> if supplied or a new instance if not.
   * @param {Object} data The plain JavaScript object bearing properties of interest.
   * @param {module:Ntnx/NicTarget} obj Optional instance to populate.
   * @param callFromChild {Boolean} Flag to recognise calling instance
   * @return {module:Ntnx/NicTarget} The populated <code>NicTarget</code> instance.
   */
  return _createClass(NicTarget, [{
    key: "getVirtualNicReference",
    value:
    /**
     * Returns Reference to the virtual NIC of the load balancer session target.
     * @return {string}
     */
    function getVirtualNicReference() {
      return this.virtualNicReference;
    }

    /**
     * Sets Reference to the virtual NIC of the load balancer session target.
     * @param {string} virtualNicReference Reference to the virtual NIC of the load balancer session target.
     */
  }, {
    key: "setVirtualNicReference",
    value: function setVirtualNicReference(virtualNicReference) {
      this.virtualNicReference = virtualNicReference;
    }

    /**
     * Returns The port value of the load balancer session target.
     * minimum: 1
     * maximum: 65535
     * @return {Number}
     */
  }, {
    key: "getPort",
    value: function getPort() {
      return this.port;
    }

    /**
     * Sets The port value of the load balancer session target.
     * @param {Number} port The port value of the load balancer session target.
     */
  }, {
    key: "setPort",
    value: function setPort(port) {
      this.port = port;
    }

    /**
     * Returns Reference to the VM of the load balancer session target.
     * @return {string}
     */
  }, {
    key: "getVmReference",
    value: function getVmReference() {
      return this.vmReference;
    }

    /**
     * Sets Reference to the VM of the load balancer session target.
     * @param {string} vmReference Reference to the VM of the load balancer session target.
     */
  }, {
    key: "setVmReference",
    value: function setVmReference(vmReference) {
      this.vmReference = vmReference;
    }

    /**
     * @return {TargetHealth}
     */
  }, {
    key: "getHealth",
    value: function getHealth() {
      return this.health;
    }

    /**
     * @param {TargetHealth} health
     */
  }, {
    key: "setHealth",
    value: function setHealth(health) {
      this.health = health;
    }
  }, {
    key: "get$Reserved",
    value: function get$Reserved() {
      return this.$reserved;
    }
  }, {
    key: "get$ObjectType",
    value: function get$ObjectType() {
      return this.$objectType;
    }
  }, {
    key: "get$UnknownFields",
    value: function get$UnknownFields() {
      return this.$unknownFields;
    }
  }, {
    key: "toJson",
    value: function toJson(forMutation) {
      if (forMutation === false) {
        return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, typeof this.getVirtualNicReference() !== 'undefined' && this.getVirtualNicReference() !== null ? {
          'virtualNicReference': this.getVirtualNicReference()
        } : {}), typeof this.getPort() !== 'undefined' && this.getPort() !== null ? {
          'port': this.getPort()
        } : {}), typeof this.getVmReference() !== 'undefined' && this.getVmReference() !== null ? {
          'vmReference': this.getVmReference()
        } : {}), typeof this.getHealth() !== 'undefined' && this.getHealth() !== null ? {
          'health': this.getHealth()
        } : {}), {}, {
          '$reserved': this.get$Reserved(),
          '$objectType': this.get$ObjectType(),
          '$unknownFields': this.get$UnknownFields()
        });
      }
      return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, typeof this.getVirtualNicReference() !== 'undefined' && this.getVirtualNicReference() !== null ? {
        'virtualNicReference': this.getVirtualNicReference()
      } : {}), typeof this.getPort() !== 'undefined' && this.getPort() !== null ? {
        'port': this.getPort()
      } : {}), typeof this.getHealth() !== 'undefined' && this.getHealth() !== null ? {
        'health': this.getHealth()
      } : {}), {}, {
        '$reserved': this.get$Reserved(),
        '$objectType': this.get$ObjectType(),
        '$unknownFields': this.get$UnknownFields()
      });
    }
  }, {
    key: "validate",
    value: function validate(scope, properties) {
      var _this = this;
      var propList = [];
      if (arguments.length === 0 || arguments.length === 1 && arguments[0] instanceof _ValidationScopes["default"]) {
        //cases validate() and validate(scope)
        propList = [];
      } else if (arguments.length === 1) {
        //case validate(properties)
        propList = arguments[0];
        scope = null;
      } else {
        //case validate(scope, properties)
        propList = arguments[1];
      }
      var res = [];
      var err = null;
      propList.forEach(function (property) {
        err = _this.validateProperty(property, scope);
        if (err) {
          res.push(err);
        }
      });
      return new Promise(function (resolve, reject) {
        if (res.length !== 0) {
          reject(err);
        } else {
          resolve();
        }
      });
    }
  }, {
    key: "validateProperty",
    value: function validateProperty(scope, property) {
      if (property === "virtualNicReference") {
        if (typeof this.virtualNicReference === 'undefined' || this.virtualNicReference === null) {
          return new _ValidationError["default"]("virtualNicReference", "undefined or null");
        }
        if (!_ValidationUtils["default"].validatePattern(this.virtualNicReference, /^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$/)) {
          return new _ValidationError["default"]("virtualNicReference", "does not satisfy required pattern: /^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$/");
        }
      }
      if (property === "port") {
        if (typeof this.port === 'undefined' || this.port === null) {
          return new _ValidationError["default"]("port", "undefined or null");
        }
        if (!_ValidationUtils["default"].validateMaximum(this.port, 65535)) {
          return new _ValidationError["default"]("port", "does not satisfy required maximum constraint: 65535");
        }
        if (!_ValidationUtils["default"].validateMinimum(this.port, 1)) {
          return new _ValidationError["default"]("port", "does not satisfy required minimum constraint: 1");
        }
      }
      if (property === "vmReference") {
        if (typeof this.vmReference === 'undefined' || this.vmReference === null) {
          return new _ValidationError["default"]("vmReference", "undefined or null");
        }
        if (!_ValidationUtils["default"].validatePattern(this.vmReference, /^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$/)) {
          return new _ValidationError["default"]("vmReference", "does not satisfy required pattern: /^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$/");
        }
      }
      if (property === "health") {
        if (typeof this.health === 'undefined' || this.health === null) {
          return new _ValidationError["default"]("health", "undefined or null");
        }
      }
      if (property === "$reserved") {
        if (typeof this.$reserved === 'undefined' || this.$reserved === null) {
          return new _ValidationError["default"]("$reserved", "undefined or null");
        }
      }
      if (property === "$objectType") {
        if (typeof this.$objectType === 'undefined' || this.$objectType === null) {
          return new _ValidationError["default"]("$objectType", "undefined or null");
        }
      }
      if (property === "$unknownFields") {
        if (typeof this.$unknownFields === 'undefined' || this.$unknownFields === null) {
          return new _ValidationError["default"]("$unknownFields", "undefined or null");
        }
      }
      return new _ValidationError["default"](property, "no such property exists");
    }
  }], [{
    key: "constructFromObject",
    value: function constructFromObject(data) {
      var obj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
      var callFromChild = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
      var items, item, i, itemArr, discriminator;
      if (data) {
        obj = obj || new NicTarget();
        if (data.hasOwnProperty('virtualNicReference') && data.virtualNicReference !== null && data.virtualNicReference !== undefined) {
          obj.setVirtualNicReference(data['virtualNicReference']);
        }
        if (data.hasOwnProperty('port') && data.port !== null && data.port !== undefined) {
          obj.setPort(data['port']);
        }
        if (data.hasOwnProperty('vmReference') && data.vmReference !== null && data.vmReference !== undefined) {
          obj.setVmReference(data['vmReference']);
        }
        if (data.hasOwnProperty('health') && data.health !== null && data.health !== undefined) {
          obj.setHealth(_TargetHealth["default"].constructFromObject(data['health']));
        }
        if (data.hasOwnProperty('$reserved')) {
          obj.$reserved = data['$reserved'];
        }
        if (data.hasOwnProperty('$objectType')) {
          obj.$objectType = data['$objectType'];
        }
        if (data.hasOwnProperty('$unknownFields')) {
          obj.$unknownFields = data['$unknownFields'];
        }
        if (!callFromChild) {
          obj.$unknownFields = _objectSpread({}, data.$unknownFields);
          for (var property in data) {
            // Check if the `property` is not already present in `obj` keys, either in snake_case or camelCase,
            // as the model's fields are generated in camelCase, but the server might return snake_case (e.g., due to standards like OIDC).
            // Also, ensure the `property` does not start with '$' and end with 'ItemDiscriminator'.
            // If all conditions are true, add the `property` from `data` to `obj.$unknownFields` as an unknown field.
            if (!Object.keys(obj).includes(property) && !Object.keys(obj).includes(this.snakeToCamel(property)) && !(property[0] === "$" && property.endsWith("ItemDiscriminator"))) {
              obj.$unknownFields[property] = data[property];
            }
          }
        }
      }
      return obj;
    }

    /**
    * Converts a given snake_case string to camelCase.
    * @param {string} snakeStr - The input string in snake_case format.
    * @returns {string} - The converted string in camelCase format.
    */
  }, {
    key: "snakeToCamel",
    value: function snakeToCamel(snakeStr) {
      return snakeStr.replace(/(_\w)/g, function (match) {
        return match[1].toUpperCase();
      });
    }
  }]);
}();
/**
 * Reference to the virtual NIC of the load balancer session target.
 * @memberof NicTarget
 */
function _toJsonMapType(obj, forMutation) {
  if (obj instanceof Map) {
    return Object.fromEntries(Array.from(obj, function (_ref) {
      var _ref2 = _slicedToArray(_ref, 2),
        k = _ref2[0],
        v = _ref2[1];
      return [k, typeof v.toJson !== "undefined" ? v.toJson(forMutation) : v];
    }));
  } else if (_typeof(obj) === 'object' && obj != null && obj.constructor === Object) {
    return Object.fromEntries(Array.from(Object.entries(obj), function (entry) {
      return [entry[0], typeof entry[1].toJson !== "undefined" ? entry[1].toJson(forMutation) : entry[1]];
    }));
  }
  return obj;
}
/*
* toJson method for a date type which serializes a Date object to proper Date or DateTime formatting
* @param {Object} obj Object to serialize
* @param {boolean} isDateOnly Boolean variable to identify Date or DateTime format for serialization
* @returns {Object|string} Returns serialized date object or original input object
*/
function _handleDateType(obj, isDateOnly) {
  if (obj instanceof Date && isDateOnly !== undefined) {
    return isDateOnly ? obj.toISOString().slice(0, 10) : obj.toISOString();
  }
  return obj;
}
NicTarget.prototype.virtualNicReference = undefined;

/**
 * The port value of the load balancer session target.
 * @memberof NicTarget
 */
NicTarget.prototype.port = undefined;

/**
 * Reference to the VM of the load balancer session target.
 * @memberof NicTarget
 */
NicTarget.prototype.vmReference = undefined;

/**
 * @memberof NicTarget
 */
NicTarget.prototype.health = undefined;
NicTarget.prototype.$reserved = undefined;
NicTarget.prototype.$objectType = undefined;
NicTarget.prototype.$unknownFields = undefined;