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

ticker: {
        type: DataTypes.TEXT,
      
      

      },

asset_name: {
        type: DataTypes.TEXT,
      
      

      },

asset_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"acao_br",


"acao_eua",


"fii",


"etf_br",


"etf_exterior",


"bdr",


"renda_fixa",


"cripto"

        ],

      },

brokerage_name: {
        type: DataTypes.TEXT,
      
      

      },

quantity: {
        type: DataTypes.DECIMAL,
      
      

      },

avg_cost: {
        type: DataTypes.DECIMAL,
      
      

      },

value_previous_year: {
        type: DataTypes.DECIMAL,
      
      

      },

value_current_year: {
        type: DataTypes.DECIMAL,
      
      

      },

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

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

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




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

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



  return investment_positions;
};


