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


"requires_confirmation",


"authorized",


"captured",


"refunded",


"failed",


"canceled"

        ],

      },

amount: {
        type: DataTypes.DECIMAL,
      
      

      },

currency: {
        type: DataTypes.TEXT,
      
      

      },

payment_method_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"card",


"bank",


"wallet",


"sandbox"

        ],

      },

merchant: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

external_transaction_key: {
        type: DataTypes.TEXT,
      
      

      },

initiated_at: {
        type: DataTypes.DATE,
      
      

      },

completed_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.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      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;
};


