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

injury_date: {
        type: DataTypes.DATE,
      
      

      },

mechanism: {
        type: DataTypes.ENUM,
      
      

        values: [

"fall",


"overuse",


"collision",


"sudden_movement",


"lifting",


"sport",


"unknown",


"other"

        ],

      },

diagnosis: {
        type: DataTypes.TEXT,
      
      

      },

affected_structure: {
        type: DataTypes.ENUM,
      
      

        values: [

"muscle",


"tendon",


"ligament",


"bone",


"nerve",


"joint",


"skin",


"other"

        ],

      },

severity: {
        type: DataTypes.ENUM,
      
      

        values: [

"mild",


"moderate",


"severe",


"grade_1",


"grade_2",


"grade_3",


"unknown"

        ],

      },

recovery_stage: {
        type: DataTypes.ENUM,
      
      

        values: [

"acute",


"subacute",


"rehab",


"return_to_sport",


"fully_recovered"

        ],

      },

initial_treatment: {
        type: DataTypes.TEXT,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  injuries.associate = (db) => {


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












































































































    db.injuries.hasMany(db.physio_exercises, {
      as: 'physio_exercises_injury',
      foreignKey: {
          name: 'injuryId',
      },
      constraints: false,
    });







//end loop



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




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

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



  return injuries;
};


