"""
Stream Processing Services (Deprecated)

This module is kept for backward compatibility with tests.
All stream processing functionality has been moved to tasks.py
for better task management and Celery integration.

Use tasks.py for all new development.
"""

import logging
from typing import Optional
from django.utils import timezone
from apps.streams.models import Channel, StreamSession, VideoConfiguration, AudioConfiguration
from . import tasks


class StreamCaptureService:
    """
    Deprecated: Use tasks.py functions instead.
    
    This class is kept for backward compatibility with existing tests.
    All functionality has been moved to Celery tasks for better management.
    """
    
    def __init__(self):
        """Initialize with deprecation warning."""
        self.logger = logging.getLogger('stream_processor.capture')
        self.logger.warning("StreamCaptureService is deprecated. Use tasks.py functions instead.")
    
    def start_capture(
        self,
        channel: Channel,
        video_config: Optional[VideoConfiguration] = None,
        audio_config: Optional[AudioConfiguration] = None
    ) -> StreamSession:
        """
        Deprecated: Use start_stream_capture task instead.
        
        This method delegates to the task-based implementation.
        """
        self.logger.warning("start_capture is deprecated. Use start_stream_capture task instead.")
        return tasks._start_capture(channel, video_config, audio_config)
    
    def stop_capture(self, session: StreamSession) -> bool:
        """
        Deprecated: Use stop_stream_capture task instead.
        
        This method delegates to the task-based implementation.
        """
        self.logger.warning("stop_capture is deprecated. Use stop_stream_capture task instead.")
        return tasks._stop_capture(session)
    
    def capture_with_retry(
        self,
        channel: Channel,
        video_config: Optional[VideoConfiguration] = None,
        audio_config: Optional[AudioConfiguration] = None
    ) -> Optional[StreamSession]:
        """
        Deprecated: Use start_stream_capture task instead.
        
        This method delegates to the task-based implementation.
        """
        self.logger.warning("capture_with_retry is deprecated. Use start_stream_capture task instead.")
        return tasks._capture_with_retry(channel, video_config, audio_config)


class HLSPlaylistManager:
    """
    Deprecated: Use tasks.py functions instead.
    
    This class is kept for backward compatibility with existing tests.
    All functionality has been moved to Celery tasks for better management.
    """
    
    def __init__(self):
        """Initialize with deprecation warning."""
        self.logger = logging.getLogger('stream_processor.hls')
        self.logger.warning("HLSPlaylistManager is deprecated. Use tasks.py functions instead.")
    
    def create_master_playlist(self, channel: Channel) -> bool:
        """
        Deprecated: Use create_playlist_for_channel task instead.
        
        This method delegates to the task-based implementation.
        """
        self.logger.warning("create_master_playlist is deprecated. Use create_playlist_for_channel task instead.")
        return tasks._create_master_playlist(channel)
    
    def cleanup_old_segments(self, channel: Channel, keep_count: Optional[int] = None) -> int:
        """
        Deprecated: Use cleanup_old_segments task instead.
        
        This method delegates to the task-based implementation.
        """
        self.logger.warning("cleanup_old_segments is deprecated. Use cleanup_old_segments task instead.")
        return tasks._cleanup_old_segments(channel, keep_count)
