"""WES v1.1 compliance test suite."""

from __future__ import annotations

import httpx

from ai4gh.compliance.runner import ComplianceSuite, TestResult, TestStatus, register_suite


@register_suite("wes")
class WESComplianceSuite(ComplianceSuite):
    """Test GA4GH WES API compliance."""

    spec_name = "wes"
    spec_version = "1.1.0"

    async def test_service_info(self) -> TestResult:
        """GET /ga4gh/wes/v1/service-info returns service info."""
        async with httpx.AsyncClient() as client:
            resp = await client.get(f"{self.base_url}/ga4gh/wes/v1/service-info")
        if resp.status_code != 200:
            return TestResult(
                name="test_service_info",
                status=TestStatus.FAIL,
                message=f"Expected 200, got {resp.status_code}",
                spec=self.spec_name,
                endpoint="/ga4gh/wes/v1/service-info",
            )
        return TestResult(
            name="test_service_info",
            status=TestStatus.PASS,
            spec=self.spec_name,
            endpoint="/ga4gh/wes/v1/service-info",
        )

    async def test_list_runs(self) -> TestResult:
        """GET /ga4gh/wes/v1/runs returns run list."""
        async with httpx.AsyncClient() as client:
            resp = await client.get(f"{self.base_url}/ga4gh/wes/v1/runs")
        if resp.status_code not in (200, 401, 403):
            return TestResult(
                name="test_list_runs",
                status=TestStatus.FAIL,
                message=f"Expected 200/401/403, got {resp.status_code}",
                spec=self.spec_name,
                endpoint="/ga4gh/wes/v1/runs",
            )
        return TestResult(
            name="test_list_runs",
            status=TestStatus.PASS,
            spec=self.spec_name,
            endpoint="/ga4gh/wes/v1/runs",
        )

    async def test_runs_response_format(self) -> TestResult:
        """Runs list should contain runs array."""
        async with httpx.AsyncClient() as client:
            resp = await client.get(f"{self.base_url}/ga4gh/wes/v1/runs")
        if resp.status_code != 200:
            return TestResult(
                name="test_runs_response_format",
                status=TestStatus.SKIP,
                message="Runs endpoint not accessible",
                spec=self.spec_name,
                endpoint="/ga4gh/wes/v1/runs",
            )
        data = resp.json()
        if "runs" not in data:
            return TestResult(
                name="test_runs_response_format",
                status=TestStatus.FAIL,
                message="Missing 'runs' in response",
                spec=self.spec_name,
                endpoint="/ga4gh/wes/v1/runs",
            )
        return TestResult(
            name="test_runs_response_format",
            status=TestStatus.PASS,
            spec=self.spec_name,
            endpoint="/ga4gh/wes/v1/runs",
        )
