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

started_at: {
        type: DataTypes.DATE,
      
      

      },

ended_at: {
        type: DataTypes.DATE,
      
      

      },

duration_minutes: {
        type: DataTypes.INTEGER,
      
      

      },

estimated_calories: {
        type: DataTypes.INTEGER,
      
      

      },

total_volume_kg: {
        type: DataTypes.DECIMAL,
      
      

      },

satisfaction_rating: {
        type: DataTypes.INTEGER,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  workout_sessions.associate = (db) => {


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


























    db.workout_sessions.hasMany(db.strength_sets, {
      as: 'strength_sets_workout_session',
      foreignKey: {
          name: 'workout_sessionId',
      },
      constraints: false,
    });

























































































//end loop



    db.workout_sessions.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.workout_sessions.belongsTo(db.workouts, {
      as: 'workout',
      foreignKey: {
        name: 'workoutId',
      },
      constraints: false,
    });




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

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



  return workout_sessions;
};


