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

income_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"dividendos",


"lci_lca_cri_cra",


"poupanca",


"fgts",


"indenizacao_rescisao",


"seguro_desemprego",


"bolsa_estudo",


"aposentadoria_parcela_isenta_65",


"ganho_acoes_ate_20k_mes",


"lucro_unico_imovel_ate_440k",


"outros"

        ],

      },

source_name: {
        type: DataTypes.TEXT,
      
      

      },

source_document: {
        type: DataTypes.TEXT,
      
      

      },

amount: {
        type: DataTypes.DECIMAL,
      
      

      },

competence: {
        type: DataTypes.TEXT,
      
      

      },

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

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

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




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

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



  return exempt_incomes;
};


