const uniqueValidator = require('mongoose-unique-validator');
module.exports = mongoose => {
    var schema = mongoose.Schema(
        {
            username: String,
            name: String,
            name_cn: String,
            email: String,
            password: String,
            roles: [{
              type: String
            }],
            mobile_phone: String,
            phone: String,
            home_phone: String,
            language: String,
            employment_status: String,
            status: String,
            address: String,
            title: String,
            title_cn: String,
            firstname: String,
            lastname: String,
            department: String,
            birth_date: String,
            driver_capacity: Number,
            date_hired: String,
            create_by: String,
            create_date: Date,
            edit_by: String,
            edit_date: Date,
            note: String,
            tags: [{
              type: String
            }],
            fetch_route_time: Date,
            site: Number
        },
        { collection: 'employee', timestamps: true }
      );
    schema.method("toJSON", function() {
        const { __v, _id, ...object } = this.toObject();
        object.id = _id;
        return object;
      });
    schema.index({username: 1, email: 1, site:1}, {unique: true});
    const Employee = mongoose.model("employee", schema);
    return Employee;
  };