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

logged_at: {
        type: DataTypes.DATE,
      
      

      },

mood_score: {
        type: DataTypes.INTEGER,
      
      

      },

emotion_tags_csv: {
        type: DataTypes.TEXT,
      
      

      },

energy_level: {
        type: DataTypes.INTEGER,
      
      

      },

anxiety_level: {
        type: DataTypes.INTEGER,
      
      

      },

contributing_factors: {
        type: DataTypes.TEXT,
      
      

      },

journal_entry: {
        type: DataTypes.TEXT,
      
      

      },

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

  mood_logs.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.mood_logs.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });



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


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

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



  return mood_logs;
};


