var _ = require('lodash'),
    moment = require('moment');

var Item = function(values) {
  values = values || {};
  _.extend(this, this._defaultValues, _.pick(values, _.keys(this._defaultValues)));
};

Item.prototype._defaultValues = {
  type: '',
  name: '',
  brand: '',
  company: '',
  company_code: null,
  address: '',
  sequence: -1,
  expiry_date: null,
};

/**
 * @api     public
 */
Item.prototype.toJSON = function() {
  return _.pick(this, _.keys(this._defaultValues));
};

/**
 * @api     public
 */
Item.prototype.expired = function() {
  var today = moment(moment().format('YYYY-MM-DD'), 'YYYY-MM-DD');
  return !moment(this.expiry_date).isBefore(today);
};

module.exports = Item;
