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

name: {
        type: DataTypes.TEXT,
      
      

      },

strategy: {
        type: DataTypes.ENUM,
      
      

        values: [

"round_robin",


"least_used",


"health_based",


"priority_weighted"

        ],

      },

rotate_every_seconds: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

error_threshold: {
        type: DataTypes.INTEGER,
      
      

      },

cooldown_seconds: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

  key_rotation_policies.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.key_rotation_policies.belongsTo(db.llm_providers, {
      as: 'provider',
      foreignKey: {
        name: 'providerId',
      },
      constraints: false,
    });

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




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

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



  return key_rotation_policies;
};


