"""
Manual video manager for handling static video collections.
"""

import json
from pathlib import Path
from typing import Dict, List, Optional, Any

def load_manual_videos(manual_file: str = "data/manual_videos.json") -> List[Dict[str, Any]]:
    """
    Load manual videos from the JSON file.
    
    Args:
        manual_file: Path to manual videos JSON file
        
    Returns:
        List of video dictionaries
    """
    manual_path = Path(manual_file)
    
    if not manual_path.exists():
        print(f"⚠️  Manual videos file not found: {manual_file}")
        return []
    
    try:
        with open(manual_path, 'r', encoding='utf-8') as f:
            data = json.load(f)
        
        videos = data.get("videos", [])
        print(f"📋 Loaded {len(videos)} manual videos from {manual_file}")
        return videos
        
    except Exception as e:
        print(f"❌ Error loading manual videos: {e}")
        return []

def get_manual_videos_for_channel(channel_name: str, manual_file: str = "data/manual_videos.json") -> List[Dict[str, Any]]:
    """
    Get manual videos for a specific channel.
    
    Args:
        channel_name: Channel name (should be "@ManualVideos")
        manual_file: Path to manual videos JSON file
        
    Returns:
        List of video dictionaries
    """
    if channel_name != "@ManualVideos":
        return []
    
    return load_manual_videos(manual_file)

def is_manual_channel(channel_url: str) -> bool:
    """
    Check if a channel URL is a manual channel.
    
    Args:
        channel_url: Channel URL
        
    Returns:
        True if it's a manual channel
    """
    return channel_url == "manual://static"

def get_manual_channel_info(channel_url: str) -> tuple[str, str]:
    """
    Get channel info for manual channels.
    
    Args:
        channel_url: Channel URL
        
    Returns:
        Tuple of (channel_name, channel_id)
    """
    if channel_url == "manual://static":
        return "@ManualVideos", "manual"
    return None, None 