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

year: {
        type: DataTypes.INTEGER,
      
      

      },

month: {
        type: DataTypes.INTEGER,
      
      

      },

asset_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"acoes",


"day_trade",


"fiis",


"etfs",


"bdrs",


"exterior",


"cripto",


"ganho_capital_bens"

        ],

      },

gross_gain: {
        type: DataTypes.DECIMAL,
      
      

      },

gross_loss: {
        type: DataTypes.DECIMAL,
      
      

      },

carryforward_loss: {
        type: DataTypes.DECIMAL,
      
      

      },

net_gain: {
        type: DataTypes.DECIMAL,
      
      

      },

tax_rate: {
        type: DataTypes.DECIMAL,
      
      

      },

tax_due: {
        type: DataTypes.DECIMAL,
      
      

      },

darf_paid: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

darf_code: {
        type: DataTypes.TEXT,
      
      

      },

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

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

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




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

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



  return monthly_capital_gains;
};


