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

label: {
        type: DataTypes.TEXT,
      
      

      },

key_fingerprint: {
        type: DataTypes.TEXT,
      
      

      },

key_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"disabled",


"rate_limited",


"compromised"

        ],

      },

last_rotated_at: {
        type: DataTypes.DATE,
      
      

      },

expires_at: {
        type: DataTypes.DATE,
      
      

      },

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

      },

requests_per_minute_limit: {
        type: DataTypes.INTEGER,
      
      

      },

daily_request_limit: {
        type: DataTypes.INTEGER,
      
      

      },

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

  llm_api_keys.associate = (db) => {


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





























//end loop



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

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




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

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



  return llm_api_keys;
};


