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

name: {
        type: DataTypes.TEXT,
      
      

      },

action_key: {
        type: DataTypes.TEXT,
      
      

      },

input_schema: {
        type: DataTypes.TEXT,
      
      

      },

output_schema: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

      },

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

  tool_actions.associate = (db) => {


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


















    db.tool_actions.hasMany(db.task_steps, {
      as: 'task_steps_tool_action',
      foreignKey: {
          name: 'tool_actionId',
      },
      constraints: false,
    });














//end loop



    db.tool_actions.belongsTo(db.tools, {
      as: 'tool',
      foreignKey: {
        name: 'toolId',
      },
      constraints: false,
    });

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




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

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



  return tool_actions;
};


