"""Pytest configuration and shared fixtures for loom-mcp.

Generated by GRIMLOCK MCP Factory
"""

import os
from typing import Generator
from unittest.mock import patch

import pytest
import respx


@pytest.fixture
def mock_env() -> Generator[None, None, None]:
    """Mock environment variables for testing.

    Yields:
        None (environment is mocked for duration of test)
    """
    env_vars = {
        "LOOM_ACCESS_TOKEN": "test-access-token-12345",
        "LOOM_BASE_URL": "https://api.loom.com/v1",
    }

    with patch.dict(os.environ, env_vars, clear=False):
        yield


@pytest.fixture
def mock_httpx_client() -> Generator[respx.MockRouter, None, None]:
    """Mock httpx client for external API calls.

    Yields:
        respx.MockRouter for configuring mock responses
    """
    with respx.mock(assert_all_called=False) as respx_mock:
        yield respx_mock


@pytest.fixture
def sample_videos_response() -> dict:
    """Sample Loom videos list response."""
    return {
        "videos": [
            {
                "id": "video-123",
                "title": "Product Demo",
                "description": "A demo of our product",
                "duration": 120,
                "created_at": "2024-01-01T00:00:00.000Z",
                "updated_at": "2024-01-02T00:00:00.000Z",
                "share_url": "https://www.loom.com/share/video-123",
                "embed_url": "https://www.loom.com/embed/video-123",
                "thumbnail_url": "https://cdn.loom.com/sessions/thumbnails/video-123.jpg",
                "status": "ready",
            },
            {
                "id": "video-456",
                "title": "Team Update",
                "description": "Weekly team standup recording",
                "duration": 300,
                "created_at": "2024-01-03T00:00:00.000Z",
                "updated_at": "2024-01-03T00:00:00.000Z",
                "share_url": "https://www.loom.com/share/video-456",
                "embed_url": "https://www.loom.com/embed/video-456",
                "thumbnail_url": "https://cdn.loom.com/sessions/thumbnails/video-456.jpg",
                "status": "ready",
            },
            {
                "id": "video-789",
                "title": "Bug Report Walkthrough",
                "description": "Showing the bug in action",
                "duration": 60,
                "created_at": "2024-01-04T00:00:00.000Z",
                "updated_at": "2024-01-04T00:00:00.000Z",
                "share_url": "https://www.loom.com/share/video-789",
                "embed_url": "https://www.loom.com/embed/video-789",
                "thumbnail_url": "https://cdn.loom.com/sessions/thumbnails/video-789.jpg",
                "status": "ready",
            },
        ],
        "total": 3,
    }


@pytest.fixture
def sample_video_detail_response() -> dict:
    """Sample Loom single video response."""
    return {
        "id": "video-123",
        "title": "Product Demo",
        "description": "A comprehensive demo of our product features",
        "duration": 120,
        "created_at": "2024-01-01T00:00:00.000Z",
        "updated_at": "2024-01-02T00:00:00.000Z",
        "share_url": "https://www.loom.com/share/video-123",
        "embed_url": "https://www.loom.com/embed/video-123",
        "thumbnail_url": "https://cdn.loom.com/sessions/thumbnails/video-123.jpg",
        "status": "ready",
        "owner": {
            "id": "user-001",
            "name": "John Doe",
            "email": "john@example.com",
        },
        "folder_id": "folder-abc",
        "privacy": "team",
        "has_transcript": True,
        "views": 42,
    }


@pytest.fixture
def sample_edit_response() -> dict:
    """Sample Loom video edit response."""
    return {
        "job_id": "edit-job-001",
        "status": "processing",
        "video_id": "video-123",
        "estimated_completion": "2024-01-05T12:00:00.000Z",
    }


@pytest.fixture
def sample_merge_response() -> dict:
    """Sample Loom video merge response."""
    return {
        "job_id": "merge-job-001",
        "status": "processing",
        "source_videos": ["video-123", "video-456"],
        "result_video_id": "video-merged-001",
        "estimated_completion": "2024-01-05T12:30:00.000Z",
    }


@pytest.fixture
def sample_empty_videos_response() -> dict:
    """Sample empty videos response."""
    return {"videos": [], "total": 0}


@pytest.fixture
def sample_folder_response() -> dict:
    """Sample folder response."""
    return {
        "id": "folder-abc",
        "name": "Product Videos",
        "video_count": 10,
        "created_at": "2024-01-01T00:00:00.000Z",
    }


@pytest.fixture
def sample_folders_response() -> dict:
    """Sample folders list response."""
    return {
        "folders": [
            {
                "id": "folder-abc",
                "name": "Product Videos",
                "video_count": 10,
            },
            {
                "id": "folder-def",
                "name": "Team Updates",
                "video_count": 25,
            },
        ]
    }
