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

payment_date: {
        type: DataTypes.DATE,
      
      

      },

amount: {
        type: DataTypes.DECIMAL,
      
      

      },

reference_no: {
        type: DataTypes.TEXT,
      
      

      },

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

  bill_payments.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.bill_payments.belongsTo(db.bills, {
      as: 'bill',
      foreignKey: {
        name: 'billId',
      },
      constraints: false,
    });

    db.bill_payments.belongsTo(db.chart_of_accounts, {
      as: 'payment_account',
      foreignKey: {
        name: 'payment_accountId',
      },
      constraints: false,
    });

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




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

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



  return bill_payments;
};


