'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

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; }; }();

var _diagnosis;

function _load_diagnosis() {
  return _diagnosis = _interopRequireDefault(require('./diagnosis'));
}

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

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

/*
  * Setting up block level variable to store class state
  * set's to null by default.
*/
var instance = null;

var DoctorRegistrar = function () {
  function DoctorRegistrar() {
    _classCallCheck(this, DoctorRegistrar);

    if (!instance) {
      instance = this;
    }

    return instance;
  }

  /**
   * Initialize the default diagnoses
   */


  _createClass(DoctorRegistrar, [{
    key: 'registerDiagnosis',


    /**
     * Register a new diagnosis
     * @param {Diagnosis} diagnosis
     */
    value: function registerDiagnosis(diagnosis) {
      this.diagnoses.push(diagnosis);
    }
  }, {
    key: 'getDiagnosisByName',
    value: function getDiagnosisByName(name) {
      return this.diagnoses.find(_checkName(name));
    }
  }], [{
    key: 'init',
    value: function init() {
      var diagnoses = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];

      var self = new DoctorRegistrar();
      self.diagnoses = diagnoses;
      // diagnoses.forEach(diagnosis => self.diagnoses.push(diagnosis));
    }

    /**
     * Get the instance of the DoctorRegistrar
     * @return {DoctorRegistrar} instance of the DoctorRegistrar
     *
     */

  }, {
    key: 'getInstance',
    value: function getInstance() {
      if (!instance) {
        DoctorRegistrar.init();
      }
      // $FlowFixMe
      return instance;
    }
  }]);

  return DoctorRegistrar;
}();

exports.default = DoctorRegistrar;


var _checkName = function _checkName(name) {
  return function (diagnosis) {
    return diagnosis.name === name;
  };
};