"""refget v2.0 compliance test suite."""

from __future__ import annotations

import httpx

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


@register_suite("refget")
class RefgetComplianceSuite(ComplianceSuite):
    """Test GA4GH refget API compliance."""

    spec_name = "refget"
    spec_version = "2.0.0"

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

    async def test_sequence_not_found(self) -> TestResult:
        """GET /sequence/<checksum> returns 404 for invalid checksum."""
        async with httpx.AsyncClient() as client:
            resp = await client.get(f"{self.base_url}/sequence/invalidchecksum123")
        if resp.status_code in (404, 400):
            return TestResult(
                name="test_sequence_not_found",
                status=TestStatus.PASS,
                spec=self.spec_name,
                endpoint="/sequence/<checksum>",
            )
        return TestResult(
            name="test_sequence_not_found",
            status=TestStatus.FAIL,
            message=f"Expected 404/400, got {resp.status_code}",
            spec=self.spec_name,
            endpoint="/sequence/<checksum>",
        )

    async def test_metadata_not_found(self) -> TestResult:
        """GET /sequence/<checksum>/metadata returns 404 for invalid checksum."""
        async with httpx.AsyncClient() as client:
            resp = await client.get(f"{self.base_url}/sequence/invalidchecksum123/metadata")
        if resp.status_code in (404, 400):
            return TestResult(
                name="test_metadata_not_found",
                status=TestStatus.PASS,
                spec=self.spec_name,
                endpoint="/sequence/<checksum>/metadata",
            )
        return TestResult(
            name="test_metadata_not_found",
            status=TestStatus.FAIL,
            message=f"Expected 404/400, got {resp.status_code}",
            spec=self.spec_name,
            endpoint="/sequence/<checksum>/metadata",
        )
