"""Tests for MCP prompts."""

from __future__ import annotations

from ai4gh.mcp.prompts import get_prompt, list_prompts


class TestListPrompts:
    def test_returns_list(self) -> None:
        prompts = list_prompts()
        assert isinstance(prompts, list)

    def test_has_prompts(self) -> None:
        prompts = list_prompts()
        assert len(prompts) == 5

    def test_prompt_structure(self) -> None:
        prompts = list_prompts()
        for p in prompts:
            assert "name" in p
            assert "description" in p
            assert "arguments" in p

    def test_prompt_names(self) -> None:
        prompts = list_prompts()
        names = {p["name"] for p in prompts}
        assert names == {
            "find_variants",
            "patient_summary",
            "rare_disease_search",
            "workflow_submit",
            "compliance_report",
        }


class TestGetPrompt:
    def test_find_variants(self) -> None:
        result = get_prompt("find_variants", {"gene": "TP53"})
        assert "TP53" in result.messages[0].content.text
        assert result.description

    def test_find_variants_defaults(self) -> None:
        result = get_prompt("find_variants", {})
        assert "BRCA1" in result.messages[0].content.text

    def test_patient_summary(self) -> None:
        result = get_prompt("patient_summary", {"phenopacket_json": '{"id": "test"}'})
        assert '{"id": "test"}' in result.messages[0].content.text

    def test_rare_disease_search(self) -> None:
        result = get_prompt("rare_disease_search", {"disease": "OMIM:100100"})
        assert "OMIM:100100" in result.messages[0].content.text

    def test_rare_disease_search_with_phenotypes(self) -> None:
        result = get_prompt(
            "rare_disease_search",
            {"disease": "test", "phenotypes": "HP:0001234,HP:0005678"},
        )
        assert "HP:0001234" in result.messages[0].content.text

    def test_workflow_submit(self) -> None:
        result = get_prompt(
            "workflow_submit",
            {"workflow_url": "https://example.com/wf.cwl", "server_url": "https://wes.example.com"},
        )
        assert "https://example.com/wf.cwl" in result.messages[0].content.text

    def test_compliance_report(self) -> None:
        result = get_prompt(
            "compliance_report",
            {"server_url": "https://beacon.example.com", "spec": "beacon"},
        )
        assert "beacon" in result.messages[0].content.text

    def test_unknown_prompt(self) -> None:
        result = get_prompt("nonexistent", {})
        assert "Unknown prompt" in result.messages[0].content.text

    def test_none_arguments(self) -> None:
        result = get_prompt("find_variants", None)
        assert result.messages
