"""Mock implementation of YouTube service for testing."""

import asyncio
import logging
from typing import Any, Dict, List, Optional

from ..protocols import YouTubeServiceProtocol

logger = logging.getLogger(__name__)


class MockYouTubeService(YouTubeServiceProtocol):
    """Mock implementation of YouTube service for testing."""

    def __init__(self, mock_data: Optional[Dict[str, Any]] = None):
        """Initialize mock YouTube service.
        
        Args:
            mock_data: Optional mock data to return for testing scenarios.
        """
        self.mock_data = mock_data or {
            "title": "Mock YouTube Video",
            "duration": 120,
            "channel": "Mock Channel",
            "description": "Mock video description",
            "upload_date": "2024-01-01",
            "view_count": 1000,
            "like_count": 100,
        }

    async def extract_metadata(self, url: str) -> Dict[str, Any]:
        """Mock metadata extraction."""
        logger.info(f"Mock extracting metadata from: {url}")
        await asyncio.sleep(0.1)  # Simulate async operation
        return self.mock_data.copy()

    async def batch_extract(self, urls: List[str]) -> List[Dict[str, Any]]:
        """Mock batch metadata extraction."""
        logger.info(f"Mock batch extracting metadata from {len(urls)} URLs")
        await asyncio.sleep(0.1)  # Simulate async operation
        
        results = []
        for url in urls:
            try:
                result = await self.extract_metadata(url)
                results.append({
                    "success": True,
                    "data": result,
                    "url": url
                })
            except Exception as e:
                results.append({
                    "success": False,
                    "error": str(e),
                    "url": url
                })
        
        return results


def create_mock_youtube_service(mock_data: Optional[Dict[str, Any]] = None) -> YouTubeServiceProtocol:
    """Create a mock YouTube service for testing."""
    return MockYouTubeService(mock_data)
