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

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"initiated",


"pending",


"succeeded",


"failed",


"refunded"

        ],

      },

provider: {
        type: DataTypes.ENUM,
      
      

        values: [

"payme",


"click",


"apelsin",


"paynet",


"manual",


"other"

        ],

      },

amount_uzs: {
        type: DataTypes.DECIMAL,
      
      

      },

provider_transaction_reference: {
        type: DataTypes.TEXT,
      
      

      },

failure_reason: {
        type: DataTypes.TEXT,
      
      

      },

initiated_at: {
        type: DataTypes.DATE,
      
      

      },

finalized_at: {
        type: DataTypes.DATE,
      
      

      },

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

  payment_transactions.associate = (db) => {


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







































//end loop



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




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

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



  return payment_transactions;
};


