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

title: {
        type: DataTypes.TEXT,
      
      

      },

publisher: {
        type: DataTypes.TEXT,
      
      

      },

published_at: {
        type: DataTypes.DATE,
      
      

      },

category: {
        type: DataTypes.ENUM,
      
      

        values: [

"stocks",


"crypto",


"earnings",


"macro",


"etfs",


"forex",


"general"

        ],

      },

url: {
        type: DataTypes.TEXT,
      
      

      },

summary: {
        type: DataTypes.TEXT,
      
      

      },

content: {
        type: DataTypes.TEXT,
      
      

      },

sentiment: {
        type: DataTypes.ENUM,
      
      

        values: [

"positive",


"neutral",


"negative",


"mixed",


"unknown"

        ],

      },

source: {
        type: DataTypes.TEXT,
      
      

      },

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

  news_articles.associate = (db) => {


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













    db.news_articles.hasMany(db.news_article_symbols, {
      as: 'news_article_symbols_news_article',
      foreignKey: {
          name: 'news_articleId',
      },
      constraints: false,
    });


    db.news_articles.hasMany(db.article_bookmarks, {
      as: 'article_bookmarks_news_article',
      foreignKey: {
          name: 'news_articleId',
      },
      constraints: false,
    });
























//end loop





    db.news_articles.hasMany(db.file, {
      as: 'cover_images',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.news_articles.getTableName(),
        belongsToColumn: 'cover_images',
      },
    });


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

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



  return news_articles;
};


