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

logged_at: {
        type: DataTypes.DATE,
      
      

      },

body_location: {
        type: DataTypes.ENUM,
      
      

        values: [

"head_neck",


"chest",


"abdomen",


"back",


"left_shoulder",


"right_shoulder",


"left_arm",


"right_arm",


"left_hip",


"right_hip",


"left_knee",


"right_knee",


"left_ankle",


"right_ankle",


"left_foot",


"right_foot",


"general",


"other"

        ],

      },

pain_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"sharp",


"dull",


"burning",


"stabbing",


"aching",


"throbbing",


"pressure"

        ],

      },

severity: {
        type: DataTypes.INTEGER,
      
      

      },

duration_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"constant",


"intermittent"

        ],

      },

better_with: {
        type: DataTypes.TEXT,
      
      

      },

worse_with: {
        type: DataTypes.TEXT,
      
      

      },

impact_level: {
        type: DataTypes.ENUM,
      
      

        values: [

"none",


"mild_limitation",


"significant_limitation",


"unable_to_function"

        ],

      },

medications_taken: {
        type: DataTypes.TEXT,
      
      

      },

journal_notes: {
        type: DataTypes.TEXT,
      
      

      },

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

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




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

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



  return pain_logs;
};


