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

title: {
        type: DataTypes.TEXT,
      
      

      },

category: {
        type: DataTypes.ENUM,
      
      

        values: [

"nutrition_science",


"fitness_exercise_science",


"mental_health",


"sleep_science",


"hormones",


"longevity_anti_ageing",


"specific_conditions",


"medications",


"lab_results_explained",


"supplements"

        ],

      },

tags_csv: {
        type: DataTypes.TEXT,
      
      

      },

reading_time_minutes: {
        type: DataTypes.INTEGER,
      
      

      },

difficulty_level: {
        type: DataTypes.ENUM,
      
      

        values: [

"beginner",


"intermediate",


"advanced"

        ],

      },

published_at: {
        type: DataTypes.DATE,
      
      

      },

updated_at_custom: {
        type: DataTypes.DATE,
      
      

      },

content: {
        type: DataTypes.TEXT,
      
      

      },

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

  library_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.library_articles.hasMany(db.saved_articles, {
      as: 'saved_articles_article',
      foreignKey: {
          name: 'articleId',
      },
      constraints: false,
    });

























































//end loop






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

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



  return library_articles;
};


