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

quantity: {
        type: DataTypes.DECIMAL,
      
      

      },

average_cost: {
        type: DataTypes.DECIMAL,
      
      

      },

market_value: {
        type: DataTypes.DECIMAL,
      
      

      },

unrealized_pl: {
        type: DataTypes.DECIMAL,
      
      

      },

realized_pl: {
        type: DataTypes.DECIMAL,
      
      

      },

day_pl: {
        type: DataTypes.DECIMAL,
      
      

      },

last_priced_at: {
        type: DataTypes.DATE,
      
      

      },

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

  paper_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.paper_positions.belongsTo(db.paper_accounts, {
      as: 'paper_account',
      foreignKey: {
        name: 'paper_accountId',
      },
      constraints: false,
    });

    db.paper_positions.belongsTo(db.market_symbols, {
      as: 'market_symbol',
      foreignKey: {
        name: 'market_symbolId',
      },
      constraints: false,
    });




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

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



  return paper_positions;
};


