import os

import httpx
import pytest


def _live_enabled() -> bool:
    return os.getenv("INTEGRATION_LIVE", "").strip() in {"1", "true", "yes"}


@pytest.mark.live
def test_live_readyz_against_docker_stack():
    if not _live_enabled():
        pytest.skip("Set INTEGRATION_LIVE=1 to run live docker-compose checks")

    base_url = os.getenv("EMBEDDING_ENGINE_URL", "http://localhost:6004")
    with httpx.Client(timeout=10.0) as client:
        health = client.get(f"{base_url}/api/v1/health/")
        assert health.status_code == 200

        readyz = client.get(f"{base_url}/api/v1/health/readyz")
        assert readyz.status_code == 200, readyz.text
        body = readyz.json()
        assert body["status"] == "ready"
        assert body["checks"]["mongo"] is True
        assert body["checks"]["redis"] is True
        assert body["checks"]["qdrant"] is True
