
import os
from azure.appconfiguration import AzureAppConfigurationClient
from azure.core.exceptions import ResourceNotFoundError

class ConfigurationManager:
    def __init__(self):
        self.APPLICATION_ENVIRONMENT = os.getenv("APPLICATION_ENVIRONMENT")
        self.AZURE_APP_CONFIG_CONNECTION_STRING = os.getenv("APP_CONFIGURATION_CONNECTION_STRING")
        self.client = AzureAppConfigurationClient.from_connection_string(self.AZURE_APP_CONFIG_CONNECTION_STRING)
        self.config_cache = {}

    def get_config_value(self, key):
        try:
            if key not in self.config_cache:
                value = self.client.get_configuration_setting(key=key, label=self.APPLICATION_ENVIRONMENT).value
                self.config_cache[key] = value
            return self.config_cache[key]
        except ResourceNotFoundError:
            return None

    def load_all_configurations(self):
        # This method loads all configurations with the specified label (environment)
        configs = {}
        for setting in self.client.list_configuration_settings(label_filter=self.APPLICATION_ENVIRONMENT):
            configs[setting.key] = setting.value
        return configs

class Configurations:
    def __init__(self):
        config_manager = ConfigurationManager()
        all_configs = config_manager.load_all_configurations()
        
        # Dynamically set attributes for each config key
        for key, value in all_configs.items():
            setattr(self, key, value)

# Create an instance of Configurations
configurations = Configurations()