"""Provider factory for managing anime content providers.

This module provides a factory class for accessing different anime content
providers (loaders). The factory uses provider identifiers (keys) to return
the appropriate provider instance.

Note: The 'key' parameter in this factory refers to the provider identifier
(e.g., 'aniworld.to'), not to be confused with series keys used within
providers to identify specific anime series.
"""

from typing import Dict

from .aniworld_provider import AniworldLoader
from .base_provider import Loader


class Loaders:
    """Factory class for managing and retrieving anime content providers.

    This factory maintains a registry of available providers and provides
    access to them via provider keys. Each provider implements the Loader
    interface for searching and downloading anime content.

    Attributes:
        dict: Dictionary mapping provider keys to provider instances.
              Provider keys are site identifiers (e.g., 'aniworld.to').
    """

    def __init__(self) -> None:
        """Initialize the provider factory with available providers.

        Currently supports:
        - 'aniworld.to': AniworldLoader for aniworld.to content
        """
        self.dict: Dict[str, Loader] = {"aniworld.to": AniworldLoader()}

    def GetLoader(self, key: str) -> Loader:
        """Retrieve a provider instance by its provider key.

        Args:
            key: Provider identifier (e.g., 'aniworld.to').
                 This is the site/provider key, not a series key.

        Returns:
            Loader instance for the specified provider.

        Raises:
            KeyError: If the provider key is not found in the registry.

        Note:
            The 'key' parameter here identifies the provider/site, while
            series-specific operations on the returned Loader use series
            keys to identify individual anime series.
        """
        return self.dict[key]
