"""TRS v2.0 compliance test suite."""

from __future__ import annotations

import httpx

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


@register_suite("trs")
class TRSComplianceSuite(ComplianceSuite):
    """Test GA4GH TRS API compliance."""

    spec_name = "trs"
    spec_version = "2.0.1"

    async def test_service_info(self) -> TestResult:
        """GET /ga4gh/trs/v2/service-info returns service info."""
        async with httpx.AsyncClient() as client:
            resp = await client.get(f"{self.base_url}/ga4gh/trs/v2/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/trs/v2/service-info",
            )
        return TestResult(
            name="test_service_info",
            status=TestStatus.PASS,
            spec=self.spec_name,
            endpoint="/ga4gh/trs/v2/service-info",
        )

    async def test_tool_classes(self) -> TestResult:
        """GET /ga4gh/trs/v2/toolClasses returns tool classes."""
        async with httpx.AsyncClient() as client:
            resp = await client.get(f"{self.base_url}/ga4gh/trs/v2/toolClasses")
        if resp.status_code != 200:
            return TestResult(
                name="test_tool_classes",
                status=TestStatus.FAIL,
                message=f"Expected 200, got {resp.status_code}",
                spec=self.spec_name,
                endpoint="/ga4gh/trs/v2/toolClasses",
            )
        data = resp.json()
        if not isinstance(data, list):
            return TestResult(
                name="test_tool_classes",
                status=TestStatus.FAIL,
                message="Expected array response",
                spec=self.spec_name,
                endpoint="/ga4gh/trs/v2/toolClasses",
            )
        return TestResult(
            name="test_tool_classes",
            status=TestStatus.PASS,
            spec=self.spec_name,
            endpoint="/ga4gh/trs/v2/toolClasses",
        )

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