"""
FMUS-VID: A Human-Centric, Comprehensive Python Video Library

FMUS-VID is designed to make video processing enjoyable, intuitive, and powerful.
It provides a clean, terse API while handling complex operations behind the scenes.

Example:
    >>> import fmusvid
    >>> video = fmusvid.load("input.mp4")
    >>> video.trim(0, 10).resize(720).grayscale().save("output.mp4")
"""

from typing import Union, List, Tuple, Optional
from pathlib import Path

from .core.video import Video
from .backends.manager import get_backend, Backend

# Import capture module - use from module import to avoid direct imports
from . import capture
# For backwards compatibility, directly expose common capture functions
capture_screen = capture.capture_screen
capture_region = capture.capture_region
record_screen = capture.record_screen
record_region = capture.record_region
select_region = capture.select_region

from .operations.composition import images_to_video, side_by_side
from .operations.basic import video_to_images, reverse_video, create_thumbnails
from .core.audio_utils import save_audio

__version__ = "0.0.1"

def load(path: Union[str, Path], backend: Union[str, Backend] = "auto", **kwargs) -> Video:
    """
    Load a video file with smart format detection.

    Args:
        path: Path to the video file
        backend: Backend to use (auto, ffmpeg, moviepy, pyav, gstreamer, vlc)
        **kwargs: Additional options (start, end, etc.)

    Returns:
        Video object

    Example:
        >>> video = fmusvid.load("input.mp4")
        >>> video = fmusvid.load("input.mp4", start=5, end=15)  # Load segment
    """
    from .core.video import Video
    return Video(path, backend=backend, **kwargs)

def create(width: int, height: int, duration: float, fps: float = 30,
           color: Tuple[int, int, int] = (0, 0, 0), **kwargs) -> Video:
    """
    Create a blank video canvas.

    Args:
        width: Width in pixels
        height: Height in pixels
        duration: Duration in seconds
        fps: Frames per second
        color: Background color as RGB tuple
        **kwargs: Additional options

    Returns:
        Video object

    Example:
        >>> canvas = fmusvid.create(1920, 1080, 10)  # 10 second blank video
    """
    from .core.video import Video
    return Video.create(width, height, duration, fps, color, **kwargs)

def concat(videos: List[Video], **kwargs) -> Video:
    """
    Concatenate multiple videos.

    Args:
        videos: List of Video objects
        **kwargs: Additional options

    Returns:
        New concatenated Video object

    Example:
        >>> combined = fmusvid.concat([video1, video2, video3])
    """
    from .core.video import Video
    return Video.concat(videos, **kwargs)

def grid(videos: List[Video], rows: int, cols: int, **kwargs) -> Video:
    """
    Arrange videos in a grid layout.

    Args:
        videos: List of Video objects
        rows: Number of rows
        cols: Number of columns
        **kwargs: Additional options

    Returns:
        New grid Video object

    Example:
        >>> grid_video = fmusvid.grid([video1, video2, video3, video4], rows=2, cols=2)
    """
    from .core.video import Video
    return Video.grid(videos, rows, cols, **kwargs)
