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

income_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"decimo_terceiro",


"plr",


"jcp",


"aplicacoes_financeiras",


"previdencia_vgbl",


"premios_loterias",


"ganho_capital_bens",


"outros"

        ],

      },

source_name: {
        type: DataTypes.TEXT,
      
      

      },

source_document: {
        type: DataTypes.TEXT,
      
      

      },

amount: {
        type: DataTypes.DECIMAL,
      
      

      },

tax_withheld: {
        type: DataTypes.DECIMAL,
      
      

      },

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

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

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




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

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



  return exclusive_incomes;
};


