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

batch_number: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"submitted",


"approved",


"processing",


"completed",


"cancelled"

        ],

      },

currency: {
        type: DataTypes.ENUM,
      
      

        values: [

"CDF",


"USD"

        ],

      },

total_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

scheduled_at: {
        type: DataTypes.DATE,
      
      

      },

processed_at: {
        type: DataTypes.DATE,
      
      

      },

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

  payment_batches.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity














































    db.payment_batches.hasMany(db.payments, {
      as: 'payments_batch',
      foreignKey: {
          name: 'batchId',
      },
      constraints: false,
    });







//end loop



    db.payment_batches.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });

    db.payment_batches.belongsTo(db.users, {
      as: 'prepared_by_user',
      foreignKey: {
        name: 'prepared_by_userId',
      },
      constraints: false,
    });




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

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



  return payment_batches;
};


