const uniqueValidator = require('mongoose-unique-validator');
module.exports = mongoose => {
    var checklistResultSchema = mongoose.Schema({
      item: String,
      result: Boolean
    });
    var schema = mongoose.Schema(
        {
            date: String,
            route_id: String,
            route_name: String,
            driver_name: String,
            checklist_result: [{
              type: checklistResultSchema
            }],
            vehicle_number: Number,
            type: String,
            head: [{
              type: String
            }],
            chinese_head: [{
              type: String
            }],
            data: [{
              type: Object
            }],
            site: Number
        },
        { collection: 'report', timestamps: true }
      );
    schema.method("toJSON", function() {
        const { __v, _id, ...object } = this.toObject();
        object.id = _id;
        return object;
      });
    schema.plugin(uniqueValidator);
    const Report = mongoose.model("report", schema);
    return Report;
  };