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

component: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"healthy",


"degraded",


"down"

        ],

      },

latency_ms: {
        type: DataTypes.DECIMAL,
      
      

      },

error_rate_percent: {
        type: DataTypes.DECIMAL,
      
      

      },

checked_at: {
        type: DataTypes.DATE,
      
      

      },

details: {
        type: DataTypes.TEXT,
      
      

      },

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

  system_health_checks.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.system_health_checks.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return system_health_checks;
};


