const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');

module.exports = function(sequelize, DataTypes) {
  const payment_methods = sequelize.define(
    'payment_methods',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

provider: {
        type: DataTypes.ENUM,
      
      

        values: [

"transfermovil",


"enzona"

        ],

      },

display_name: {
        type: DataTypes.TEXT,
      
      

      },

is_enabled: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

instructions: {
        type: DataTypes.TEXT,
      
      

      },

      importHash: {
        type: DataTypes.STRING(255),
        allowNull: true,
        unique: true,
      },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

  payment_methods.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity











    db.payment_methods.hasMany(db.payments, {
      as: 'payments_payment_method',
      foreignKey: {
          name: 'payment_methodId',
      },
      constraints: false,
    });









//end loop





    db.payment_methods.hasMany(db.file, {
      as: 'qr_images',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.payment_methods.getTableName(),
        belongsToColumn: 'qr_images',
      },
    });


    db.payment_methods.belongsTo(db.users, {
      as: 'createdBy',
    });

    db.payment_methods.belongsTo(db.users, {
      as: 'updatedBy',
    });
  };



  return payment_methods;
};


