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

detected_at: {
        type: DataTypes.DATE,
      
      

      },

detection_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"anomaly",


"malware",


"phishing",


"ransomware",


"lateral_movement",


"data_exfiltration",


"policy_violation"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"new",


"triaged",


"confirmed",


"false_positive",


"suppressed"

        ],

      },

confidence: {
        type: DataTypes.DECIMAL,
      
      

      },

risk_score: {
        type: DataTypes.DECIMAL,
      
      

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

evidence: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

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

    db.detections.belongsTo(db.telemetry_events, {
      as: 'event',
      foreignKey: {
        name: 'eventId',
      },
      constraints: false,
    });

    db.detections.belongsTo(db.ai_models, {
      as: 'model',
      foreignKey: {
        name: 'modelId',
      },
      constraints: false,
    });




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

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



  return detections;
};


