"""Shared fixtures for arxivy tests."""

import pytest

from arxivy.models import Author, Paper

# ── Sample Atom XML Responses ────────────────────────────────

SAMPLE_ENTRY_XML = """\
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:arxiv="http://arxiv.org/schemas/atom">
  <id>http://arxiv.org/abs/1706.03762v7</id>
  <updated>2023-08-02T01:31:28Z</updated>
  <published>2017-06-12T17:57:34Z</published>
  <title>Attention Is All You Need</title>
  <summary>The dominant sequence transduction models are based on complex recurrent or
convolutional neural networks. We propose a new simple network architecture, the
Transformer, based solely on attention mechanisms.</summary>
  <author>
    <name>Ashish Vaswani</name>
    <arxiv:affiliation>Google Brain</arxiv:affiliation>
  </author>
  <author>
    <name>Noam Shazeer</name>
    <arxiv:affiliation>Google Brain</arxiv:affiliation>
  </author>
  <author>
    <name>Niki Parmar</name>
  </author>
  <link href="http://arxiv.org/abs/1706.03762v7" rel="alternate" type="text/html"/>
  <link title="pdf" href="http://arxiv.org/pdf/1706.03762v7" rel="related" type="application/pdf"/>
  <arxiv:primary_category term="cs.CL"/>
  <category term="cs.CL"/>
  <category term="cs.LG"/>
  <arxiv:comment>15 pages, 5 figures</arxiv:comment>
  <arxiv:journal_ref>Advances in Neural Information Processing Systems 30 (NIPS 2017)</arxiv:journal_ref>
  <arxiv:doi>10.48550/arXiv.1706.03762</arxiv:doi>
</entry>"""

SAMPLE_SEARCH_FEED = f"""\
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"
      xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"
      xmlns:arxiv="http://arxiv.org/schemas/atom">
  <title>ArXiv Query: search_query=all:attention is all you need</title>
  <id>http://arxiv.org/api/query</id>
  <opensearch:totalResults>1</opensearch:totalResults>
  <opensearch:startIndex>0</opensearch:startIndex>
  <opensearch:itemsPerPage>1</opensearch:itemsPerPage>
  {SAMPLE_ENTRY_XML}
</feed>"""

SAMPLE_EMPTY_FEED = """\
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"
      xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"
      xmlns:arxiv="http://arxiv.org/schemas/atom">
  <title>ArXiv Query: search_query=all:nonexistent</title>
  <id>http://arxiv.org/api/query</id>
  <opensearch:totalResults>0</opensearch:totalResults>
  <opensearch:startIndex>0</opensearch:startIndex>
  <opensearch:itemsPerPage>0</opensearch:itemsPerPage>
</feed>"""

# arXiv returns an entry with an error message as title for invalid ID lookups
SAMPLE_NOT_FOUND_FEED = """\
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"
      xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"
      xmlns:arxiv="http://arxiv.org/schemas/atom">
  <title>ArXiv Query: id_list=9999.99999</title>
  <id>http://arxiv.org/api/query</id>
  <opensearch:totalResults>0</opensearch:totalResults>
  <opensearch:startIndex>0</opensearch:startIndex>
  <opensearch:itemsPerPage>1</opensearch:itemsPerPage>
  <entry>
    <id>http://arxiv.org/api/errors#incorrect_id_format_for_9999.99999</id>
    <title/>
    <summary>Error</summary>
  </entry>
</feed>"""

SAMPLE_MULTI_FEED = """\
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"
      xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"
      xmlns:arxiv="http://arxiv.org/schemas/atom">
  <title>ArXiv Query: id_list=1706.03762,2010.11929</title>
  <id>http://arxiv.org/api/query</id>
  <opensearch:totalResults>2</opensearch:totalResults>
  <opensearch:startIndex>0</opensearch:startIndex>
  <opensearch:itemsPerPage>2</opensearch:itemsPerPage>
  <entry>
    <id>http://arxiv.org/abs/1706.03762v7</id>
    <published>2017-06-12T17:57:34Z</published>
    <updated>2023-08-02T01:31:28Z</updated>
    <title>Attention Is All You Need</title>
    <summary>The Transformer model.</summary>
    <author><name>Ashish Vaswani</name></author>
    <link href="http://arxiv.org/abs/1706.03762v7" rel="alternate" type="text/html"/>
    <link title="pdf" href="http://arxiv.org/pdf/1706.03762v7" rel="related" type="application/pdf"/>
    <arxiv:primary_category term="cs.CL"/>
    <category term="cs.CL"/>
  </entry>
  <entry>
    <id>http://arxiv.org/abs/2010.11929v2</id>
    <published>2020-10-22T17:40:49Z</published>
    <updated>2021-06-03T17:12:02Z</updated>
    <title>An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale</title>
    <summary>Vision Transformer (ViT).</summary>
    <author><name>Alexey Dosovitskiy</name></author>
    <link href="http://arxiv.org/abs/2010.11929v2" rel="alternate" type="text/html"/>
    <link title="pdf" href="http://arxiv.org/pdf/2010.11929v2" rel="related" type="application/pdf"/>
    <arxiv:primary_category term="cs.CV"/>
    <category term="cs.CV"/>
    <category term="cs.AI"/>
    <category term="cs.LG"/>
  </entry>
</feed>"""


@pytest.fixture
def sample_paper():
    """A parsed Paper matching the SAMPLE_ENTRY_XML."""
    return Paper(
        arxiv_id="1706.03762",
        title="Attention Is All You Need",
        summary=(
            "The dominant sequence transduction models are based on complex recurrent or "
            "convolutional neural networks. We propose a new simple network architecture, the "
            "Transformer, based solely on attention mechanisms."
        ),
        authors=[
            Author(name="Ashish Vaswani", affiliation="Google Brain"),
            Author(name="Noam Shazeer", affiliation="Google Brain"),
            Author(name="Niki Parmar", affiliation=""),
        ],
        published="2017-06-12T17:57:34Z",
        updated="2023-08-02T01:31:28Z",
        categories=["cs.CL", "cs.LG"],
        primary_category="cs.CL",
        comment="15 pages, 5 figures",
        journal_ref="Advances in Neural Information Processing Systems 30 (NIPS 2017)",
        doi="10.48550/arXiv.1706.03762",
        pdf_url="http://arxiv.org/pdf/1706.03762v7",
        abstract_url="http://arxiv.org/abs/1706.03762v7",
    )
