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

name: {
        type: DataTypes.TEXT,
      
      

      },

kind: {
        type: DataTypes.ENUM,
      
      

        values: [

"api",


"browser_automation",


"native_app_mock",


"sandbox"

        ],

      },

base_url: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

      },

docs_url: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  tool_providers.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_providers.hasMany(db.tools, {
      as: 'tools_provider',
      foreignKey: {
          name: 'providerId',
      },
      constraints: false,
    });



















//end loop



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




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

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



  return tool_providers;
};


