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

debt_code: {
        type: DataTypes.TEXT,
      
      

      },

creditor_name: {
        type: DataTypes.TEXT,
      
      

      },

creditor_document: {
        type: DataTypes.TEXT,
      
      

      },

description_text: {
        type: DataTypes.TEXT,
      
      

      },

balance_previous_year: {
        type: DataTypes.DECIMAL,
      
      

      },

balance_current_year: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  debts.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.debts.belongsTo(db.declarations, {
      as: 'declaration',
      foreignKey: {
        name: 'declarationId',
      },
      constraints: false,
    });

    db.debts.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return debts;
};


