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 DestNewsletterSchema = new Schema({
  idapp: {
    type: String,
  },
  descr: {
    type: String,
  },
  tipodest_id: {
    type: Number,
  },
});

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

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

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

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

};


DestNewsletterSchema.statics.findAllIdApp = async function (idapp) {
  const DestNewsletter = this;

  const myfind = { idapp };

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


const DestNewsletter = mongoose.model('DestNewsletter', DestNewsletterSchema);

DestNewsletter.createIndexes()
  .then(() => { })
  .catch((err) => { throw err; });


module.exports = { DestNewsletter };
