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

name: {
        type: DataTypes.TEXT,
      
      

      },

asset_class: {
        type: DataTypes.ENUM,
      
      

        values: [

"stock",


"etf",


"crypto",


"forex"

        ],

      },

sector: {
        type: DataTypes.TEXT,
      
      

      },

market_cap_min: {
        type: DataTypes.DECIMAL,
      
      

      },

market_cap_max: {
        type: DataTypes.DECIMAL,
      
      

      },

pe_min: {
        type: DataTypes.DECIMAL,
      
      

      },

pe_max: {
        type: DataTypes.DECIMAL,
      
      

      },

price_min: {
        type: DataTypes.DECIMAL,
      
      

      },

price_max: {
        type: DataTypes.DECIMAL,
      
      

      },

volume_min: {
        type: DataTypes.DECIMAL,
      
      

      },

performance_52w_min: {
        type: DataTypes.DECIMAL,
      
      

      },

performance_52w_max: {
        type: DataTypes.DECIMAL,
      
      

      },

is_pinned: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  screener_filters.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity























    db.screener_filters.hasMany(db.screener_runs, {
      as: 'screener_runs_screener_filter',
      foreignKey: {
          name: 'screener_filterId',
      },
      constraints: false,
    });















//end loop



    db.screener_filters.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });




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

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



  return screener_filters;
};


