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_number: {
        type: DataTypes.TEXT,
      
      

      },

refund_method: {
        type: DataTypes.ENUM,
      
      

        values: [

"cash",


"card",


"mobile_money",


"store_credit"

        ],

      },

amount: {
        type: DataTypes.DECIMAL,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"requested",


"approved",


"paid",


"rejected"

        ],

      },

requested_at: {
        type: DataTypes.DATE,
      
      

      },

approved_at: {
        type: DataTypes.DATE,
      
      

      },

reason: {
        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.sales, {
      as: 'sale',
      foreignKey: {
        name: 'saleId',
      },
      constraints: false,
    });

    db.refunds.belongsTo(db.users, {
      as: 'requested_by',
      foreignKey: {
        name: 'requested_byId',
      },
      constraints: false,
    });

    db.refunds.belongsTo(db.users, {
      as: 'approved_by',
      foreignKey: {
        name: 'approved_byId',
      },
      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;
};


