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

name: {
        type: DataTypes.TEXT,
      
      

      },

cluster_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"kubernetes",


"gpu_cluster",


"storage_cluster",


"edge_fleet"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"healthy",


"degraded",


"down"

        ],

      },

region: {
        type: DataTypes.TEXT,
      
      

      },

provider: {
        type: DataTypes.TEXT,
      
      

      },

api_gateway_url: {
        type: DataTypes.TEXT,
      
      

      },

cpu_capacity: {
        type: DataTypes.DECIMAL,
      
      

      },

gpu_capacity: {
        type: DataTypes.DECIMAL,
      
      

      },

storage_capacity_tb: {
        type: DataTypes.DECIMAL,
      
      

      },

last_audit_at: {
        type: DataTypes.DATE,
      
      

      },

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

  infrastructure_clusters.associate = (db) => {


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
























    db.infrastructure_clusters.hasMany(db.edge_sensors, {
      as: 'edge_sensors_cluster',
      foreignKey: {
          name: 'clusterId',
      },
      constraints: false,
    });





//end loop



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




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

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



  return infrastructure_clusters;
};


