var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var request = new Schema({
  basic: {
    project: String,
    system: String,
    subsystem: String,
    signal: String,
    cableType: String,
    engineer: String,
    service: String,
    wbs: String,
    tags: [String],
    quantity: {type: Number, min: 1}
  },

  from: {
    building: String,
    area: String,
    room: String,
    rack: String,
    elevation: Number,
    unit: String,
    terminationDevice: String,
    terminationType: String,
    wiringDrawing: String,
    label: String
  },

  to: {
    building: String,
    area: String,
    room: String,
    rack: String,
    elevation: Number,
    unit: String,
    terminationDevice: String,
    terminationType: String,
    wiringDrawing: String,
    label: String
  },

  // routing: {
  //   trayGroup: String,
  //   penetration: String,
  //   penetrationZ: String
  // },

  // other: {
    // fabricatedBy: String,
    // terminatedBy: String,
    // comments: String
  // },
  comments: String,
  status: Number,
  createdBy: String,
  createdOn: Date,
  updatedBy: String,
  updatedOn: Date,
  submittedBy: String,
  submittedOn: Date,
  // adjustedBy: String,
  // adjustedOn: Date,
  approvedBy: String,
  approvedOn: Date,
  rejectedBy: String,
  rejectedOn: Date
});

var cable = new Schema({
  request_id: String,
  number: String,
  tags: [String],
  status: Number,
  submittedBy: String,
  submittedOn: Date,
  approvedBy: String,
  approvedOn: Date,
  updatedOn: Date,
  updatedBy: String,
  orderedBy: String,
  orderedOn: Date,
  receivedBy: String,
  receivedOn: Date,
  acceptedBy: String,
  acceptedOn: Date,
  labeledBy: String,
  labeledOn: Date,
  benchTerminatedBy: String,
  benchTerminatedOn: Date,
  benchTestedBy: String,
  benchTestedOn: Date,
  pulledBy: String,
  pulledOn: Date,
  fieldTerminatedBy: String,
  fieldTerminatedOn: Date,
  fieldTestedBy: String,
  fieldTestedOn: Date
});

var Request = mongoose.model('Request', request);
var Cable = mongoose.model('Cable', cable);


module.exports = {
  Cable: Cable,
  Request: Request
};
@@ -300,16 +300,23 @@
 ntity: %7B
+%0A      
 type: Nu
@@ -324,15 +324,26 @@
 ber,
+%0A     
  min: 1
+%0A    
 %7D%0A  
@@ -941,18 +941,16 @@
 ther: %7B%0A
-  
   // fab
@@ -970,18 +970,16 @@
 ring,%0A  
- 
- 
 // termi
@@ -995,18 +995,16 @@
 String,%0A
-  
   // com
@@ -1376,30 +1376,64 @@
 ,%0A  number: 
-String
+%7B%0A    type: String,%0A    unique: true%0A  %7D
 ,%0A  tags: %5BS

make the cable number unique