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

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"processing",


"completed",


"rejected",


"cancelled"

        ],

      },

coins_amount: {
        type: DataTypes.INTEGER,
      
      

      },

cash_amount_uzs: {
        type: DataTypes.DECIMAL,
      
      

      },

payout_method: {
        type: DataTypes.ENUM,
      
      

        values: [

"bank_transfer",


"mobile_money",


"e_wallet"

        ],

      },

payout_destination: {
        type: DataTypes.TEXT,
      
      

      },

provider_reference: {
        type: DataTypes.TEXT,
      
      

      },

admin_note: {
        type: DataTypes.TEXT,
      
      

      },

requested_at: {
        type: DataTypes.DATE,
      
      

      },

processed_at: {
        type: DataTypes.DATE,
      
      

      },

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

  withdrawal_requests.associate = (db) => {


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















    db.withdrawal_requests.hasMany(db.payment_transactions, {
      as: 'payment_transactions_withdrawal_request',
      foreignKey: {
          name: 'withdrawal_requestId',
      },
      constraints: false,
    });

























//end loop



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




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

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



  return withdrawal_requests;
};


