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

measured_at: {
        type: DataTypes.DATE,
      
      

      },

metric_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"blood_pressure",


"resting_heart_rate",


"spo2",


"body_temperature",


"blood_glucose",


"hba1c",


"cholesterol_panel",


"full_blood_count",


"liver_function",


"kidney_function",


"thyroid_panel",


"iron_studies",


"vitamin_levels",


"mineral_levels",


"hormones",


"inflammation_markers",


"metabolic_panel",


"cardiac_markers",


"urine_analysis",


"hrv",


"body_composition",


"waist_circumference",


"hip_circumference",


"neck_circumference",


"body_measurements",


"dexa_scan",


"lung_function",


"skin_health_marker",


"intraocular_pressure",


"resting_metabolic_rate"

        ],

      },

value_primary: {
        type: DataTypes.DECIMAL,
      
      

      },

value_secondary: {
        type: DataTypes.DECIMAL,
      
      

      },

unit: {
        type: DataTypes.TEXT,
      
      

      },

panel_json: {
        type: DataTypes.TEXT,
      
      

      },

device_used: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

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




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

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



  return health_metrics;
};


