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

name: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

tool_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"policy_explainer",


"graphic_idea_generator",


"caption_generator",


"document_formatter",


"other"

        ],

      },

prompt_template: {
        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,
    },
  );

  ai_tools.associate = (db) => {


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

























    db.ai_tools.hasMany(db.ai_tool_runs, {
      as: 'ai_tool_runs_tool',
      foreignKey: {
          name: 'toolId',
      },
      constraints: false,
    });




//end loop






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

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



  return ai_tools;
};


