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,
      },

transaction_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"authorization",


"capture",


"refund",


"payout",


"chargeback"

        ],

      },

transaction_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"succeeded",


"failed",


"canceled"

        ],

      },

amount: {
        type: DataTypes.DECIMAL,
      
      

      },

currency: {
        type: DataTypes.TEXT,
      
      

      },

provider: {
        type: DataTypes.TEXT,
      
      

      },

provider_reference: {
        type: DataTypes.TEXT,
      
      

      },

processed_at: {
        type: DataTypes.DATE,
      
      

      },

failure_reason: {
        type: DataTypes.TEXT,
      
      

      },

      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.orders, {
      as: 'order',
      foreignKey: {
        name: 'orderId',
      },
      constraints: false,
    });

    db.payment_transactions.belongsTo(db.tenants, {
      as: 'buyer_tenant',
      foreignKey: {
        name: 'buyer_tenantId',
      },
      constraints: false,
    });

    db.payment_transactions.belongsTo(db.tenants, {
      as: 'seller_tenant',
      foreignKey: {
        name: 'seller_tenantId',
      },
      constraints: false,
    });

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




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

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



  return payment_transactions;
};


