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

name: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"dormant",


"ended"

        ],

      },

start_at: {
        type: DataTypes.DATE,
      
      

      },

end_at: {
        type: DataTypes.DATE,
      
      

      },

summary: {
        type: DataTypes.TEXT,
      
      

      },

global_risk_score: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  threat_campaigns.associate = (db) => {

    db.threat_campaigns.belongsToMany(db.threat_indicators, {
      as: 'indicators',
      foreignKey: {
        name: 'threat_campaigns_indicatorsId',
      },
      constraints: false,
      through: 'threat_campaignsIndicatorsThreat_indicators',
    });

    db.threat_campaigns.belongsToMany(db.threat_indicators, {
      as: 'indicators_filter',
      foreignKey: {
        name: 'threat_campaigns_indicatorsId',
      },
      constraints: false,
      through: 'threat_campaignsIndicatorsThreat_indicators',
    });


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




























//end loop



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

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




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

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



  return threat_campaigns;
};


