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

firm_name: {
        type: DataTypes.TEXT,
      
      

      },

rating: {
        type: DataTypes.ENUM,
      
      

        values: [

"strong_buy",


"buy",


"hold",


"sell",


"strong_sell"

        ],

      },

price_target: {
        type: DataTypes.DECIMAL,
      
      

      },

rating_at: {
        type: DataTypes.DATE,
      
      

      },

summary: {
        type: DataTypes.TEXT,
      
      

      },

source_url: {
        type: DataTypes.TEXT,
      
      

      },

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

  analyst_ratings.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.analyst_ratings.belongsTo(db.market_symbols, {
      as: 'market_symbol',
      foreignKey: {
        name: 'market_symbolId',
      },
      constraints: false,
    });




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

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



  return analyst_ratings;
};


