"""VCR integration tests for SemanticScholarClient."""

from __future__ import annotations

from typing import Any

import pytest

from axm_bib.clients.semantic_scholar import SemanticScholarClient
from axm_bib.models import Paper


@pytest.mark.vcr
class TestSemanticScholarVCR:
    """Replay recorded S2 API responses."""

    def test_search_paper(self, vcr_cassette: Any) -> None:
        """Search returns parsed Paper objects from real API response."""
        client = SemanticScholarClient()
        papers = client.search_paper("attention is all you need", limit=3)

        assert isinstance(papers, list)
        assert len(papers) > 0
        assert all(isinstance(p, Paper) for p in papers)
        assert all(p.source == "semantic_scholar" for p in papers)
        # The famous Transformer paper should have a title
        assert any("attention" in p.title.lower() for p in papers)

    def test_get_paper(self, vcr_cassette: Any) -> None:
        """Direct paper lookup returns a Paper with correct fields."""
        client = SemanticScholarClient()
        paper = client.get_paper("ARXIV:1706.03762")

        assert paper is not None
        assert isinstance(paper, Paper)
        assert "attention" in paper.title.lower()
        assert paper.source == "semantic_scholar"
