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_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

refunded_at: {
        type: DataTypes.DATE,
      
      

      },

refund_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"succeeded",


"failed",


"canceled"

        ],

      },

reason: {
        type: DataTypes.TEXT,
      
      

      },

provider_reference: {
        type: DataTypes.TEXT,
      
      

      },

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




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

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



  return refunds;
};


