"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
var ObjectId = require('bson').ObjectID;
var tv4 = require('tv4');
var Sublocation = /*#__PURE__*/function () {
  function Sublocation(opt) {
    _classCallCheck(this, Sublocation);
    this._id = null;
    this.inventoryId = null;
    this.buildingId = null;
    this.buildingName = '';
    this.floorId = null;
    this.floorName = '';
    this.roomId = null;
    this.roomNumber = null;
    this.name = null;
    this.barcode = null;
    this.temperature = null;
    this.pressure = null;
    this.isPrivate = false;
    this.hazardCodes = [];
    this.pictogramCodes = [];
    if (opt) {
      this.fillObject(opt);
    }
  }
  _createClass(Sublocation, [{
    key: "fillObject",
    value: function fillObject(opt) {
      var _this = this;
      this._id = new ObjectId(opt._id);
      this.inventoryId = ObjectId.isValid(opt.inventoryId) ? new ObjectId(opt.inventoryId) : null;
      this.buildingId = opt.buildingId;
      this.buildingName = opt.buildingName || '';
      this.floorId = opt.floorId;
      this.floorName = opt.floorName || '';
      this.roomId = opt.roomId;
      this.roomNumber = opt.roomNumber;
      this.name = opt.name || null;
      this.barcode = opt.barcode || '';
      this.temperature = opt.temperature || null;
      this.pressure = opt.pressure || null;
      this.isPrivate = opt.isPrivate || false;
      if (opt.hazardCodes) {
        opt.hazardCodes.forEach(function (code) {
          return _this.hazardCodes.push(code);
        });
      }
      if (opt.pictogramCodes) {
        opt.pictogramCodes.forEach(function (code) {
          return _this.pictogramCodes.push(code);
        });
      }
    }
  }, {
    key: "validate",
    value: function validate() {
      return tv4.validateMultiple(this, Sublocation.schema());
    }
  }], [{
    key: "schema",
    value: function schema() {
      return {
        $schema: 'http://json-schema.org/draft-04/schema#',
        id: 'sublocation.schema.json',
        type: 'object',
        properties: {
          _id: {
            type: 'object'
          },
          inventoryId: {
            type: 'object'
          },
          buildingId: {
            type: 'string'
          },
          buildingName: {
            type: 'string'
          },
          floorId: {
            type: 'string'
          },
          floorName: {
            type: 'string'
          },
          roomId: {
            type: 'string'
          },
          roomNumber: {
            type: 'string'
          },
          name: {
            type: 'string'
          },
          barcode: {
            type: ['string', null]
          },
          temperature: {
            type: 'string'
          },
          pressure: {
            type: 'string'
          },
          isPrivate: {
            type: 'boolean'
          },
          hazardCodes: {
            type: 'array',
            item: {
              type: 'string'
            }
          },
          pictogramCodes: {
            type: 'array',
            item: {
              type: 'string'
            }
          }
        },
        required: Object.keys(this)
      };
    }
  }]);
  return Sublocation;
}();
module.exports = Sublocation;