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

scenario_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"phishing",


"ransomware",


"malware_outbreak",


"insider_threat",


"cloud_misconfig",


"lateral_movement",


"ddos"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"running",


"completed",


"failed",


"canceled"

        ],

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

ended_at: {
        type: DataTypes.DATE,
      
      

      },

success_score: {
        type: DataTypes.DECIMAL,
      
      

      },

findings: {
        type: DataTypes.TEXT,
      
      

      },

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

  simulation_runs.associate = (db) => {

    db.simulation_runs.belongsToMany(db.assets, {
      as: 'affected_assets',
      foreignKey: {
        name: 'simulation_runs_affected_assetsId',
      },
      constraints: false,
      through: 'simulation_runsAffected_assetsAssets',
    });

    db.simulation_runs.belongsToMany(db.assets, {
      as: 'affected_assets_filter',
      foreignKey: {
        name: 'simulation_runs_affected_assetsId',
      },
      constraints: false,
      through: 'simulation_runsAffected_assetsAssets',
    });


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




























//end loop



    db.simulation_runs.belongsTo(db.simulation_labs, {
      as: 'lab',
      foreignKey: {
        name: 'labId',
      },
      constraints: false,
    });

    db.simulation_runs.belongsTo(db.users, {
      as: 'initiated_by',
      foreignKey: {
        name: 'initiated_byId',
      },
      constraints: false,
    });

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




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

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



  return simulation_runs;
};


