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 TemplEmailSchema = new Schema({
  idapp: {
    type: String,
  },
  subject: {
    type: String,
  },
  testoheadermail: {
    type: String,
  },
  content: {
    type: String,
  },
  img: {
    type: String,
  },
  content2: {
    type: String,
  },
  img2: {
    type: String,
  },

  options: [{
    type: String,
  }]
});

TemplEmailSchema.statics.getFieldsForSearch = function () {
  return []
};

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

TemplEmailSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {

  return await tools.DuplicateAllRecords(this, idapporig, idappdest);

};


TemplEmailSchema.statics.findAllIdApp = async function (idapp) {
  const TemplEmail = this;

  const myfind = { idapp };

  return await TemplEmail.find(myfind).lean();
};


const TemplEmail = mongoose.model('TemplEmail', TemplEmailSchema);

module.exports = { TemplEmail };
