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

last_price: {
        type: DataTypes.DECIMAL,
      
      

      },

market_cap: {
        type: DataTypes.DECIMAL,
      
      

      },

pe_ratio: {
        type: DataTypes.DECIMAL,
      
      

      },

volume: {
        type: DataTypes.DECIMAL,
      
      

      },

performance_52w: {
        type: DataTypes.DECIMAL,
      
      

      },

sector: {
        type: DataTypes.TEXT,
      
      

      },

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

  screener_results.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.screener_results.belongsTo(db.screener_runs, {
      as: 'screener_run',
      foreignKey: {
        name: 'screener_runId',
      },
      constraints: false,
    });

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




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

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



  return screener_results;
};


