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

period_end_at: {
        type: DataTypes.DATE,
      
      

      },

reported_at: {
        type: DataTypes.DATE,
      
      

      },

reported_eps: {
        type: DataTypes.DECIMAL,
      
      

      },

estimated_eps: {
        type: DataTypes.DECIMAL,
      
      

      },

surprise: {
        type: DataTypes.DECIMAL,
      
      

      },

surprise_percent: {
        type: DataTypes.DECIMAL,
      
      

      },

reported_revenue: {
        type: DataTypes.DECIMAL,
      
      

      },

estimated_revenue: {
        type: DataTypes.DECIMAL,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

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




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

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



  return earnings_reports;
};


