"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 _require = require('bson'),
  ObjectId = _require.ObjectId;
var tv4 = require('tv4');
var clone = require('clone');
var LineItem = /*#__PURE__*/function () {
  function LineItem(opt) {
    _classCallCheck(this, LineItem);
    this._id = null;
    this.description = null;
    this.catalogNumber = null;
    this.vendor = null;
    this.cas = [];
    this.quantity = 1;
    this.amount = null;
    this.units = null;
    this.details = null;
    this.leadTime = null;
    this.taxable = null;
    this.unitPrice = null;
    this.shippingCharge = null;
    this.handlingCharge = null;
    this.tax1 = null;
    this.tax2 = null;
    if (opt) {
      this.fillObject(clone(opt));
    }
  }
  _createClass(LineItem, [{
    key: "fillObject",
    value: function fillObject(opt) {
      this._id = new ObjectId(opt._id);
      this.description = opt.description || null;
      this.catalogNumber = opt.catalogNumber || null;
      this.vendor = opt.vendor || null;
      this.cas = opt.cas || null;
      this.quantity = opt.quantity || 1;
      this.amount = opt.amount || null;
      this.units = opt.units || null;
      this.details = opt.details || null;
      this.leadTime = opt.leadTime || null;
      this.taxable = opt.taxable || null;
      this.unitPrice = opt.unitPrice || null;
      this.shippingCharge = opt.shippingCharge || null;
      this.handlingCharge = opt.handlingCharge || null;
      this.tax1 = opt.tax1 || null;
      this.tax2 = opt.tax2 || null;
    }
  }, {
    key: "validate",
    value: function validate() {
      return tv4.validateMultiple(this, LineItem.schema());
    }
  }], [{
    key: "schema",
    value: function schema() {
      return {
        $schema: 'http://json-schema.org/draft-04/schema#',
        id: 'line-item.schema.json',
        type: 'object',
        additionalProperties: false,
        properties: {
          _id: {
            type: 'object'
          },
          description: {
            type: ['string', 'null']
          },
          catalogNumber: {
            type: ['string', 'null']
          },
          vendor: {
            type: ['string', 'null']
          },
          cas: {
            type: 'array',
            items: {
              type: 'string'
            }
          },
          quantity: {
            type: 'number'
          },
          amount: {
            type: ['number', 'null']
          },
          units: {
            type: 'string'
          },
          details: {
            type: ['object', 'null']
          },
          leadTime: {
            type: ['string', 'null']
          },
          taxable: {
            type: ['string', 'null']
          },
          unitPrice: {
            type: ['string', 'null']
          },
          shippingCharge: {
            type: ['string', 'null']
          },
          handlingCharge: {
            type: ['string', 'null']
          },
          tax1: {
            type: ['string', 'null']
          },
          tax2: {
            type: ['string', 'null']
          }
        },
        required: ['_id', 'amount', 'units']
      };
    }
  }]);
  return LineItem;
}();
module.exports = LineItem;