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

name: {
        type: DataTypes.TEXT,
      
      

      },

model_code: {
        type: DataTypes.TEXT,
      
      

      },

max_input_tokens: {
        type: DataTypes.INTEGER,
      
      

      },

max_output_tokens: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

      },

price_per_million_input_tokens: {
        type: DataTypes.DECIMAL,
      
      

      },

price_per_million_output_tokens: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

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

  llm_models.associate = (db) => {


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














    db.llm_models.hasMany(db.chats, {
      as: 'chats_model',
      foreignKey: {
          name: 'modelId',
      },
      constraints: false,
    });
















//end loop



    db.llm_models.belongsTo(db.llm_providers, {
      as: 'provider',
      foreignKey: {
        name: 'providerId',
      },
      constraints: false,
    });

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




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

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



  return llm_models;
};


