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

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

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

PaymentTypeSchema.statics.findAllIdApp = async function (idapp) {
  const PaymentType = this;

  const myfind = { idapp };

  return await tools.findAllQueryIdApp(this, myfind);

};

const PaymentType = mongoose.model('Paymenttype', PaymentTypeSchema);

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


module.exports = { PaymentType };
