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

name: {
        type: DataTypes.TEXT,
      
      

      },

system_prompt: {
        type: DataTypes.TEXT,
      
      

      },

model_family: {
        type: DataTypes.ENUM,
      
      

        values: [

"openai",


"anthropic",


"google",


"local",


"mock"

        ],

      },

model_name: {
        type: DataTypes.TEXT,
      
      

      },

temperature: {
        type: DataTypes.DECIMAL,
      
      

      },

max_output_tokens: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

  assistant_profiles.associate = (db) => {


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









    db.assistant_profiles.hasMany(db.conversations, {
      as: 'conversations_assistant_profile',
      foreignKey: {
          name: 'assistant_profileId',
      },
      constraints: false,
    });























//end loop



    db.assistant_profiles.belongsTo(db.workspaces, {
      as: 'workspace',
      foreignKey: {
        name: 'workspaceId',
      },
      constraints: false,
    });

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




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

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



  return assistant_profiles;
};


