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

recommended_at: {
        type: DataTypes.DATE,
      
      

      },

reason_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"stage_based",


"symptom_based",


"caregiver_interest",


"clinician_selected",


"trending"

        ],

      },

reason_text: {
        type: DataTypes.TEXT,
      
      

      },

state: {
        type: DataTypes.ENUM,
      
      

        values: [

"new",


"viewed",


"saved",


"dismissed"

        ],

      },

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

  article_recommendations.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.article_recommendations.belongsTo(db.patients, {
      as: 'patient',
      foreignKey: {
        name: 'patientId',
      },
      constraints: false,
    });

    db.article_recommendations.belongsTo(db.scientific_articles, {
      as: 'article',
      foreignKey: {
        name: 'articleId',
      },
      constraints: false,
    });

    db.article_recommendations.belongsTo(db.accounts, {
      as: 'accounts',
      foreignKey: {
        name: 'accountsId',
      },
      constraints: false,
    });




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

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



  return article_recommendations;
};


