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 payout_methods = sequelize.define(
    'payout_methods',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

method_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"bank_card",


"bank_transfer",


"paypal",


"webmoney",


"yookassa",


"robokassa",


"crypto"

        ],

      },

method_label: {
        type: DataTypes.TEXT,
      
      

      },

account_identifier: {
        type: DataTypes.TEXT,
      
      

      },

holder_name: {
        type: DataTypes.TEXT,
      
      

      },

country: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"disabled",


"needs_verification"

        ],

      },

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

  payout_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.payout_methods.hasMany(db.withdrawal_requests, {
      as: 'withdrawal_requests_payout_method',
      foreignKey: {
          name: 'payout_methodId',
      },
      constraints: false,
    });
















//end loop



    db.payout_methods.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.payout_methods.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return payout_methods;
};


