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

action_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"isolate_host",


"block_ip",


"block_domain",


"disable_user",


"reset_credentials",


"quarantine_file",


"kill_process",


"revoke_token",


"rotate_keys",


"patch",


"restore_backup",


"notify",


"create_ticket"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"running",


"succeeded",


"failed",


"canceled",


"requires_approval"

        ],

      },

requested_at: {
        type: DataTypes.DATE,
      
      

      },

executed_at: {
        type: DataTypes.DATE,
      
      

      },

target: {
        type: DataTypes.TEXT,
      
      

      },

action_result: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  response_actions.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.response_actions.belongsTo(db.incidents, {
      as: 'incident',
      foreignKey: {
        name: 'incidentId',
      },
      constraints: false,
    });

    db.response_actions.belongsTo(db.response_playbooks, {
      as: 'playbook',
      foreignKey: {
        name: 'playbookId',
      },
      constraints: false,
    });

    db.response_actions.belongsTo(db.users, {
      as: 'requested_by',
      foreignKey: {
        name: 'requested_byId',
      },
      constraints: false,
    });

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




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

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



  return response_actions;
};


