const uniqueValidator = require('mongoose-unique-validator');
module.exports = mongoose => {
    var schema = mongoose.Schema(
        {
            // Legacy fields
            message_name: String,
            message_group: Number,
            message_body: String,
            // New sent message fields
            title: String,
            language: String,
            sent_date: Date,
            message: String,
            recipient_name: String,
            recipient_id: String,
            message_title: String,
            create_by: String,
            create_date: Date,
            site: Number
        },
        { collection: 'message_template', timestamps: true }
      );
    schema.method("toJSON", function() {
        const { __v, _id, ...object } = this.toObject();
        object.id = _id;
        return object;
      });
    schema.plugin(uniqueValidator);
    const Message = mongoose.model("message", schema);
    return Message;
  };