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

event_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"request",


"redirect",


"callback",


"webhook",


"status_check"

        ],

      },

result: {
        type: DataTypes.ENUM,
      
      

        values: [

"success",


"failure",


"ignored"

        ],

      },

message: {
        type: DataTypes.TEXT,
      
      

      },

event_at: {
        type: DataTypes.DATE,
      
      

      },

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

  payment_events.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_events.belongsTo(db.payments, {
      as: 'payment',
      foreignKey: {
        name: 'paymentId',
      },
      constraints: false,
    });



    db.payment_events.hasMany(db.file, {
      as: 'payload_files',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.payment_events.getTableName(),
        belongsToColumn: 'payload_files',
      },
    });


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

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



  return payment_events;
};


