import requests
from typing import List, Dict, Any

class LiteratureReview:
    """Fetches, organizes, and summarizes scientific papers for citation and review."""
    def __init__(self):
        self.papers: List[Dict[str, Any]] = []

    def fetch_arxiv(self, query: str, max_results: int = 5) -> List[Dict[str, Any]]:
        url = f"http://export.arxiv.org/api/query?search_query=all:{query}&start=0&max_results={max_results}"
        response = requests.get(url)
        # For demo: just store the raw XML
        self.papers.append({"query": query, "raw": response.text})
        return self.papers

    def add_paper(self, title: str, authors: List[str], summary: str, link: str):
        self.papers.append({"title": title, "authors": authors, "summary": summary, "link": link})

    def summarize_papers(self) -> List[str]:
        return [f"{p['title']} by {', '.join(p['authors'])}: {p['summary']}" for p in self.papers if 'title' in p]

    def get_bibliography(self) -> List[str]:
        return [p.get('link', '') for p in self.papers]
