{"size": 1174, "ext": "js", "max_stars_repo_path": "models/Device.js", "max_stars_repo_name": "BlueCC8/iot-simulator-api", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "models/Device.js", "max_issues_repo_name": "BlueCC8/iot-simulator-api", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "models/Device.js", "max_forks_repo_name": "BlueCC8/iot-simulator-api", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 17.7878787879, "max_line_length": 56, "alphanum_fraction": 0.5928449744}
const mongoose = require('mongoose');

const { Schema } = mongoose;
const validate = require('mongoose-validator');

const currencyValidator = [
  validate({
    validator: 'isCurrency',
    message: 'Invalid currency'
  })
];
// const urlValidator = [
//   validate({
//     validator: 'isURL',
//     message: 'Invalid URL'
//   })
// ];
const DeviceSchema = new Schema({
  devName: {
    type: String,
    trim: true,
    required: [true, 'Why no name?'],
    minlength: [3, 'Too few characters']
  },
  appLayerID: {
    type: Schema.Types.ObjectId,
    ref: 'ApplicationLayer'
  },
  tranLayer: {
    type: String,
    trim: true
  },
  netLayerID: {
    type: Schema.Types.ObjectId,
    ref: 'NetworkLayer'
  },
  linLayerID: {
    type: Schema.Types.ObjectId,
    ref: 'LinkLayer'
  },
  devPrice: {
    type: String,
    trim: true,
    min: 0,
    validate: currencyValidator
  },
  username: {
    type: String,
    ref: 'Users'
  },
  devProducer: {
    type: String,
    trim: true
  },
  devImgUrl: {
    type: String,
    trim: true
  },
  updated_date: {
    type: Date,
    default: Date.now
  }
});

module.exports = mongoose.model('Device', DeviceSchema);
