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

exercise_name: {
        type: DataTypes.TEXT,
      
      

      },

exercise_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"strength",


"cardio",


"mobility",


"stretch",


"skill"

        ],

      },

primary_muscle_group: {
        type: DataTypes.ENUM,
      
      

        values: [

"full_body",


"upper_body",


"lower_body",


"core",


"chest",


"back",


"shoulders",


"arms",


"glutes",


"legs"

        ],

      },

equipment: {
        type: DataTypes.ENUM,
      
      

        values: [

"none_bodyweight",


"dumbbells",


"barbell",


"bands",


"machines",


"trx",


"kettlebell",


"cable",


"medicine_ball",


"other"

        ],

      },

instructions: {
        type: DataTypes.TEXT,
      
      

      },

common_mistakes: {
        type: DataTypes.TEXT,
      
      

      },

coaching_cues: {
        type: DataTypes.TEXT,
      
      

      },

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

  exercises.associate = (db) => {


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






















    db.exercises.hasMany(db.workout_exercises, {
      as: 'workout_exercises_exercise',
      foreignKey: {
          name: 'exerciseId',
      },
      constraints: false,
    });





    db.exercises.hasMany(db.strength_sets, {
      as: 'strength_sets_exercise',
      foreignKey: {
          name: 'exerciseId',
      },
      constraints: false,
    });



















































































    db.exercises.hasMany(db.physio_exercises, {
      as: 'physio_exercises_exercise',
      foreignKey: {
          name: 'exerciseId',
      },
      constraints: false,
    });







//end loop





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


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

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



  return exercises;
};


