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

snapshotted_at: {
        type: DataTypes.DATE,
      
      

      },

total_value: {
        type: DataTypes.DECIMAL,
      
      

      },

cash_value: {
        type: DataTypes.DECIMAL,
      
      

      },

positions_value: {
        type: DataTypes.DECIMAL,
      
      

      },

day_pl: {
        type: DataTypes.DECIMAL,
      
      

      },

all_time_pl: {
        type: DataTypes.DECIMAL,
      
      

      },

day_pl_percent: {
        type: DataTypes.DECIMAL,
      
      

      },

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

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




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

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



  return portfolio_snapshots;
};


