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

payer_cnpj: {
        type: DataTypes.TEXT,
      
      

      },

payer_name: {
        type: DataTypes.TEXT,
      
      

      },

taxable_income: {
        type: DataTypes.DECIMAL,
      
      

      },

official_deductions: {
        type: DataTypes.DECIMAL,
      
      

      },

inss_withheld: {
        type: DataTypes.DECIMAL,
      
      

      },

tax_withheld: {
        type: DataTypes.DECIMAL,
      
      

      },

thirteenth_salary: {
        type: DataTypes.DECIMAL,
      
      

      },

informe_document_url: {
        type: DataTypes.TEXT,
      
      

      },

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

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

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




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

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



  return income_payers_pj;
};


