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

name: {
        type: DataTypes.TEXT,
      
      

      },

agent_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"autonomous_soc_agent",


"automation_engine",


"self_healing_network_controller"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"online",


"offline",


"degraded",


"training"

        ],

      },

capabilities: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

last_heartbeat_at: {
        type: DataTypes.DATE,
      
      

      },

actions_success_rate: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  soc_agents.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.soc_agents.belongsTo(db.ai_models, {
      as: 'model',
      foreignKey: {
        name: 'modelId',
      },
      constraints: false,
    });

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




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

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



  return soc_agents;
};


