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

occurred_at: {
        type: DataTypes.DATE,
      
      

      },

event_kind: {
        type: DataTypes.ENUM,
      
      

        values: [

"scan",


"intrusion_attempt",


"malware_delivery",


"phishing",


"ddos",


"ransomware",


"c2_activity",


"data_exfiltration"

        ],

      },

source_country: {
        type: DataTypes.TEXT,
      
      

      },

source_ip: {
        type: DataTypes.TEXT,
      
      

      },

destination_country: {
        type: DataTypes.TEXT,
      
      

      },

destination_ip: {
        type: DataTypes.TEXT,
      
      

      },

latitude: {
        type: DataTypes.DECIMAL,
      
      

      },

longitude: {
        type: DataTypes.DECIMAL,
      
      

      },

risk_score: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  attack_map_events.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.attack_map_events.belongsTo(db.threat_indicators, {
      as: 'indicator',
      foreignKey: {
        name: 'indicatorId',
      },
      constraints: false,
    });

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




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

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



  return attack_map_events;
};


