# from .logger import Logger  # fix: commented, circular import
from tools.common import AttributeManager



class _Defaults:
    """
    Singleton-like container for the application's default logger instance.
    This class acts as a registry to avoid circular dependencies between the Logger and its sub-components.
    """
    __slots__ = ('__logger',)

    __instance = None


    def __new__(cls, *args, **kwargs):
        """ Ensure only one instance of _Defaults exists. """
        if cls.__instance is None:
            cls.__instance = super(_Defaults, cls).__new__(cls)
        return cls.__instance


    def __init__(self, logger=None):
        """
        Initialize the default container.

        :param logger: The logger instance to be used as default.
        """

        if logger is not None:
            self.__logger = logger
        elif not AttributeManager.has_attribute(obj=self, attr='__logger'):
            self.__logger = None

        pass


    @property
    def logger(self):
        """
        Get the current default logger instance.

        :return: Logger instance or None.
        """
        return self.__logger


    @logger.setter
    def logger(self, logger):
        """
        Update the default logger instance.

        :param logger: New logger instance.
        """
        self.__logger = logger
        pass

    pass



Defaults = _Defaults()
