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 ContribtypeSchema = new Schema({
  idapp: {
    type: String,
  },
  label: {
    type: String,
  },
  showprice: {
    type: Boolean,
  }
});

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

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

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

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

};


ContribtypeSchema.statics.findAllIdApp = async function (idapp) {
  const Contribtype = this;

  const myfind = { idapp };

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

const Contribtype = mongoose.model('Contribtype', ContribtypeSchema);

module.exports = { Contribtype };
