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

indicator_value: {
        type: DataTypes.TEXT,
      
      

      },

indicator_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"ip",


"domain",


"url",


"hash",


"email",


"certificate",


"user_agent"

        ],

      },

confidence: {
        type: DataTypes.ENUM,
      
      

        values: [

"low",


"medium",


"high"

        ],

      },

severity: {
        type: DataTypes.ENUM,
      
      

        values: [

"low",


"medium",


"high",


"critical"

        ],

      },

first_seen_at: {
        type: DataTypes.DATE,
      
      

      },

last_seen_at: {
        type: DataTypes.DATE,
      
      

      },

source: {
        type: DataTypes.TEXT,
      
      

      },

context: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  threat_indicators.associate = (db) => {


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



















    db.threat_indicators.hasMany(db.attack_map_events, {
      as: 'attack_map_events_indicator',
      foreignKey: {
          name: 'indicatorId',
      },
      constraints: false,
    });










//end loop



    db.threat_indicators.belongsTo(db.threat_actors, {
      as: 'threat_actor',
      foreignKey: {
        name: 'threat_actorId',
      },
      constraints: false,
    });

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




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

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



  return threat_indicators;
};


