"""Medium priority job API tests."""

from __future__ import annotations

from typing import TYPE_CHECKING

import pytest
from fastapi.testclient import TestClient

if TYPE_CHECKING:
    from sqlalchemy.orm import Session


class TestJobStatus:
    """Test job status endpoints."""

    def test_get_job_status_not_found(
        self,
        test_client: TestClient,
    ):
        """Verify 404 for non-existent job."""
        response = test_client.get("/api/v1/jobs/nonexistent-job-id")
        
        assert response.status_code == 404
        data = response.json()
        assert "not found" in data["detail"].lower()

    def test_get_job_status_includes_timestamps(
        self,
        test_client: TestClient,
        test_db_session: "Session",
    ):
        """Verify timestamp fields."""
        # This test requires a real job to be created
        # For now, we'll test the error case
        response = test_client.get("/api/v1/jobs/test-job-id")
        
        # If job doesn't exist, we get 404
        # If job exists, we should check for timestamps
        if response.status_code == 200:
            data = response.json()
            assert "created_at" in data
            assert "updated_at" in data


class TestJobStreaming:
    """Test job streaming endpoints."""

    def test_stream_job_progress_not_found(
        self,
        test_client: TestClient,
    ):
        """Verify 404 handling."""
        response = test_client.get("/api/v1/jobs/stream/nonexistent-job-id")
        
        # Streaming endpoint may return 404 or start streaming
        # Implementation dependent
        assert response.status_code in [200, 404]

    def test_stream_job_progress_sse_format(
        self,
        test_client: TestClient,
    ):
        """Verify SSE format compliance."""
        # This test requires a real job
        # For now, we'll test the not found case
        response = test_client.get("/api/v1/jobs/stream/test-job-id")
        
        if response.status_code == 200:
            # Check Content-Type for SSE (may include charset parameter)
            content_type = response.headers.get("content-type", "")
            assert content_type.startswith("text/event-stream")

