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

trade_date: {
        type: DataTypes.DATE,
      
      

      },

ticker: {
        type: DataTypes.TEXT,
      
      

      },

operation: {
        type: DataTypes.ENUM,
      
      

        values: [

"buy",


"sell"

        ],

      },

quantity: {
        type: DataTypes.DECIMAL,
      
      

      },

unit_price: {
        type: DataTypes.DECIMAL,
      
      

      },

fees: {
        type: DataTypes.DECIMAL,
      
      

      },

ir_operation_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"comum",


"day_trade",


"fii",


"bdr",


"exterior",


"cripto",


"renda_fixa"

        ],

      },

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

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

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




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

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



  return trades;
};


