"""
Factory for creating MusicBrainz data providers.
Provides a clean way to instantiate the appropriate data provider based on configuration.
"""

from typing import Optional
from ..api.database import MusicBrainzDatabase
from ..api.api_client import MusicBrainzAPIClient
from .interfaces import MusicBrainzDataProvider
from ..config.constants import DEFAULT_MUSICBRAINZ_URL


class DataProviderFactory:
    """Factory for creating MusicBrainz data providers."""
    
    @staticmethod
    def create_provider(use_database: bool = True, base_url: str = DEFAULT_MUSICBRAINZ_URL) -> MusicBrainzDataProvider:
        """
        Create a data provider based on configuration.
        
        Args:
            use_database: Whether to use database (True) or API (False)
            base_url: Base URL for API client (only used if use_database=False)
            
        Returns:
            MusicBrainzDataProvider instance
        """
        if use_database:
            provider = MusicBrainzDatabase()
            if provider.connect():
                return provider
            else:
                print("⚠️  Database connection failed, falling back to API")
                return MusicBrainzAPIClient(base_url)
        else:
            return MusicBrainzAPIClient(base_url) 