"""Debug script to test real PubMed article fields."""
import os, sys, asyncio
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))

os.environ["DATABASE_URL"] = "postgresql+asyncpg://scilit:scilit_dev@localhost:5432/scilit"
os.environ["JWT_SECRET"] = "dev-secret-change-in-production"
os.environ["DEBUG"] = "true"
os.environ["SPECIALTY"] = "oncology"

from app.services.pubmed_api import fetch_articles as fetch_pubmed_articles


async def main():
    # Test with 5 well-known PMIDs that should have chemicals
    pmids = [39266661, 38890137, 39310948, 38270939, 38310458]
    print(f"Fetching {pmids}...")
    articles = await fetch_pubmed_articles(pmids)

    for a in articles:
        print(f"\n─── PMID {a['pmid']} ───")
        print(f"  Title: {a.get('title', '')[:60]}")

        chem = a.get("chemical_list", [])
        print(f"  chemical_list ({len(chem)}): {[c.get('name','') for c in chem]}")

        genes = a.get("gene_symbols", [])
        print(f"  gene_symbols: {genes}")

        refs = a.get("num_refs")
        print(f"  num_refs: {refs}")

        status = a.get("publication_status")
        print(f"  publication_status: {status}")

        ad = a.get("article_date")
        print(f"  article_date: {ad}")

        db = a.get("databank_list", [])
        print(f"  databank_list ({len(db)}): {[d.get('databank_name','') for d in db]}")

        sm = a.get("suppl_mesh_list", [])
        print(f"  suppl_mesh_list ({len(sm)}): {[s.get('descriptor','') for s in sm]}")


asyncio.run(main())
