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

refund_reference: {
        type: DataTypes.TEXT,
      
      

      },

amount: {
        type: DataTypes.DECIMAL,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"requested",


"processing",


"succeeded",


"failed",


"cancelled"

        ],

      },

reason: {
        type: DataTypes.TEXT,
      
      

      },

requested_at: {
        type: DataTypes.DATE,
      
      

      },

completed_at: {
        type: DataTypes.DATE,
      
      

      },

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

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




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

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



  return refunds;
};


