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

name: {
        type: DataTypes.TEXT,
      
      

      },

node_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"sfu",


"turn",


"signaling_gateway",


"recorder_worker",


"ai_service",


"edge_cache"

        ],

      },

region: {
        type: DataTypes.ENUM,
      
      

        values: [

"us",


"eu",


"apac",


"sa",


"me"

        ],

      },

zone: {
        type: DataTypes.TEXT,
      
      

      },

endpoint: {
        type: DataTypes.TEXT,
      
      

      },

health_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"healthy",


"degraded",


"unhealthy",


"draining",


"offline"

        ],

      },

last_heartbeat_at: {
        type: DataTypes.DATE,
      
      

      },

cpu_utilization: {
        type: DataTypes.DECIMAL,
      
      

      },

memory_utilization: {
        type: DataTypes.DECIMAL,
      
      

      },

current_conferences: {
        type: DataTypes.INTEGER,
      
      

      },

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

  conference_nodes.associate = (db) => {


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




















    db.conference_nodes.hasMany(db.sfu_allocations, {
      as: 'sfu_allocations_conference_node',
      foreignKey: {
          name: 'conference_nodeId',
      },
      constraints: false,
    });




































//end loop



    db.conference_nodes.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return conference_nodes;
};


