"""Health endpoint test — AC1-2: Extended health check with DB, Redis, storage, worker."""

from __future__ import annotations

import pytest
from httpx import AsyncClient


@pytest.mark.asyncio
class TestHealth:
    """AC1: GET /api/v1/health -> 200 without auth, with extended checks."""

    async def test_health_returns_200_without_auth(self, client: AsyncClient):
        """AC1: GET /api/v1/health -> 200 without auth."""
        resp = await client.get("/api/v1/health")
        assert resp.status_code == 200
        data = resp.json()
        assert "status" in data
        assert "version" in data
        assert "checks" in data

    async def test_health_has_database_check(self, client: AsyncClient):
        """AC1: Health response includes checks.database."""
        resp = await client.get("/api/v1/health")
        assert resp.status_code == 200
        data = resp.json()
        assert "database" in data["checks"]
        assert "status" in data["checks"]["database"]

    async def test_health_has_redis_check(self, client: AsyncClient):
        """AC1: Health response includes checks.redis."""
        resp = await client.get("/api/v1/health")
        assert resp.status_code == 200
        data = resp.json()
        assert "redis" in data["checks"]
        assert "status" in data["checks"]["redis"]

    async def test_health_has_storage_check(self, client: AsyncClient):
        """AC1: Health response includes checks.storage."""
        resp = await client.get("/api/v1/health")
        assert resp.status_code == 200
        data = resp.json()
        assert "storage" in data["checks"]
        assert "status" in data["checks"]["storage"]

    async def test_health_has_worker_check(self, client: AsyncClient):
        """AC1: Health response includes checks.worker."""
        resp = await client.get("/api/v1/health")
        assert resp.status_code == 200
        data = resp.json()
        assert "worker" in data["checks"]
        assert "status" in data["checks"]["worker"]

    async def test_health_status_is_valid_value(self, client: AsyncClient):
        """Health status should be 'healthy' or 'degraded'."""
        resp = await client.get("/api/v1/health")
        assert resp.status_code == 200
        data = resp.json()
        assert data["status"] in ("healthy", "degraded")
