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

name: {
        type: DataTypes.TEXT,
      
      

      },

category: {
        type: DataTypes.ENUM,
      
      

        values: [

"containment",


"eradication",


"recovery",


"notification",


"hunting",


"enrichment"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"active",


"disabled"

        ],

      },

trigger_conditions: {
        type: DataTypes.TEXT,
      
      

      },

steps: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

expected_duration_minutes: {
        type: DataTypes.DECIMAL,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

  response_playbooks.associate = (db) => {


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














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















//end loop



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




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

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



  return response_playbooks;
};


