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

allocation_date: {
        type: DataTypes.DATE,
      
      

      },

amount_allocated: {
        type: DataTypes.DECIMAL,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

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

    db.payment_allocations.belongsTo(db.invoices, {
      as: 'invoice',
      foreignKey: {
        name: 'invoiceId',
      },
      constraints: false,
    });

    db.payment_allocations.belongsTo(db.companies, {
      as: 'companies',
      foreignKey: {
        name: 'companiesId',
      },
      constraints: false,
    });




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

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



  return payment_allocations;
};


