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

bedtime: {
        type: DataTypes.DATE,
      
      

      },

sleep_onset_time: {
        type: DataTypes.DATE,
      
      

      },

awakenings_count: {
        type: DataTypes.INTEGER,
      
      

      },

final_wake_time: {
        type: DataTypes.DATE,
      
      

      },

out_of_bed_time: {
        type: DataTypes.DATE,
      
      

      },

total_sleep_minutes: {
        type: DataTypes.INTEGER,
      
      

      },

sleep_quality: {
        type: DataTypes.INTEGER,
      
      

      },

dream_recall: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

dream_notes: {
        type: DataTypes.TEXT,
      
      

      },

morning_energy: {
        type: DataTypes.INTEGER,
      
      

      },

sleep_aids_used: {
        type: DataTypes.TEXT,
      
      

      },

disturbances: {
        type: DataTypes.TEXT,
      
      

      },

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

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




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

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



  return sleep_logs;
};


