# Adtlas TV Advertising Platform - Channels App Configuration
# This module configures the channels Django application
"""Channels App Configuration

This module contains the Django app configuration for the channels app.
It handles app initialization and signal registration.

The channels app manages:
- TV channel configurations
- Regional settings and zones
- Codec configurations
- jingles
- Provider-specific settings
"""

from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _


class ChannelsConfig(AppConfig):
    """
    Django application configuration for the Channels app.
    
    This app manages TV channels, broadcasting networks, geographic zones,
    and their complex relationships within the Adtlas TV advertising platform.
    
    Features:
    - TV Channel management with detailed metadata
    - Broadcasting Network hierarchies and affiliations
    - Geographic Zone definitions for targeted advertising
    - Content Schedule integration with Electronic Program Guide (EPG)
    - Audience Demographics and viewership analytics
    - Advertising Inventory management per channel/zone
    """
    
    # Django app configuration
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'apps.channels'
    verbose_name = _('TV Channels & Networks')
    
    # App metadata
    description = _(
        'Comprehensive TV channel and network management system for '
        'targeted advertising and audience analytics'
    )
    version = '1.0.0'
    
    def ready(self):
        """
        Perform initialization when Django starts.
        
        This method is called when the app is ready and all models are loaded.
        It's used to register signal handlers, perform app-specific setup,
        and initialize any required services.
        """
        try:
            # Import signal handlers to register them
            from . import signals  # noqa: F401
            
            # Log successful app initialization
            import logging
            logger = logging.getLogger(__name__)
            logger.info(
                f"Channels app v{self.version} initialized successfully. "
                f"Ready to manage TV channels, networks, and zones."
            )
            
        except ImportError:
            # Signals module doesn't exist yet, which is fine during initial setup
            pass
        except Exception as e:
            # Log any initialization errors
            import logging
            logger = logging.getLogger(__name__)
            logger.error(
                f"Error initializing Channels app: {e}",
                exc_info=True
            )