const mongoose = require('mongoose').set('debug', false)
const Schema = mongoose.Schema;

const tools = require('../tools/general');

mongoose.Promise = global.Promise;
mongoose.level = "F";


// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
  schema.options.usePushEach = true
});

const OpzEmailSchema = new Schema({
  key: {
    type: String,
    default: ''
  },
  label_it: {
    type: String,
  }
});


OpzEmailSchema.statics.getFieldsForSearch = function () {
  return [{field: 'label_it', type: tools.FieldType.string}]
};

OpzEmailSchema.statics.executeQueryTable = function (idapp, params) {
  params.fieldsearch = this.getFieldsForSearch();
  return tools.executeQueryTable(this, 0, params);
};

OpzEmailSchema.statics.findAllIdApp = async function (idapp) {
  const OpzEmail = this;

  return await OpzEmail.find({}, (err, arrrec) => {
    return arrrec
  });
};


const OpzEmail = mongoose.model('OpzEmail', OpzEmailSchema);

module.exports = { OpzEmail };
