var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

import { SettingDefPropsValidator } from './SettingDefPropsValidator';
import { SettingDefPropsChoice } from './SettingDefPropsChoice';

export var SettingDefProps = function () {
  /**
   * @param {String} type
   * @param {String} name
   * @param {String} title
   * @param {String|Boolean} defaultValue
   * @param {Boolean} required
   * @param {{}|null} validator
   * @param {Boolean} serverOnly
   * @param {Boolean|null} multi
   * @param {Array.<{}>|null} choices
   */
  function SettingDefProps(_ref) {
    var type = _ref.type,
        name = _ref.name,
        title = _ref.title,
        defaultValue = _ref.defaultValue,
        required = _ref.required,
        validator = _ref.validator,
        serverOnly = _ref.serverOnly,
        multi = _ref.multi,
        choices = _ref.choices;

    _classCallCheck(this, SettingDefProps);

    this.state = {
      type: type,
      defaultValue: defaultValue,
      required: required,
      validator: validator,
      serverOnly: serverOnly,
      multi: multi,
      choices: choices
    };
  }

  /**
   * @return {String}
   */


  _createClass(SettingDefProps, [{
    key: 'type',
    get: function get() {
      return this.state.type;
    }

    /**
     * @return {String}
     */

  }, {
    key: 'name',
    get: function get() {
      return this.state.name;
    }

    /**
     * @return {String}
     */

  }, {
    key: 'title',
    get: function get() {
      return this.state.title;
    }

    /**
     * @return {String|Boolean}
     */

  }, {
    key: 'defaultValue',
    get: function get() {
      return this.state.defaultValue;
    }

    /**
     * @return {Boolean}
     */

  }, {
    key: 'required',
    get: function get() {
      return this.state.required;
    }

    /**
     * @return {SettingDefPropsValidator|null}
     */

  }, {
    key: 'validator',
    get: function get() {
      if (this.state.validator) {
        var props = JSON.parse(JSON.stringify(this.state.validator));
        return new SettingDefPropsValidator(props);
      }

      return null;
    }

    /**
     * type {boolean}
     */

  }, {
    key: 'serverOnly',
    get: function get() {
      return !!this.state.serverOnly;
    }

    /**
     * @return {Boolean|null}
     */

  }, {
    key: 'multi',
    get: function get() {
      if (this.state.multi === true || this.state.multi === false) {
        return this.state.multi;
      }

      return null;
    }

    /**
     * @return {Array.<SettingDefPropsChoice>}
     */

  }, {
    key: 'choices',
    get: function get() {
      if (this.state.choices instanceof Array) {
        return this.state.choices.map(function (choice) {
          return new SettingDefPropsChoice(Object.assign({}, choice));
        });
      }
    }
  }]);

  return SettingDefProps;
}();