use paper_gap::sources::{self, DiscoverKind, ProviderKind, SourceFilter};

#[test]
fn filters_paper_and_repo_sources() {
    let papers = sources::filter(sources::builtin(), SourceFilter::Papers);
    assert!(papers.iter().any(|p| p.id == "arxiv"));
    assert!(papers.iter().all(|p| matches!(
        p.kind,
        ProviderKind::Paper | ProviderKind::Metadata | ProviderKind::Both
    )));

    let repos = sources::filter(sources::builtin(), SourceFilter::Repos);
    assert!(repos.iter().any(|p| p.id == "github"));
    assert!(repos.iter().any(|p| p.id == "gitlab"));
    assert!(repos.iter().any(|p| p.id == "codeberg"));
    assert!(repos.iter().all(|p| p.kind == ProviderKind::Repo));
}

#[test]
fn discovery_queries_cover_all_kinds() {
    assert!(
        sources::discovery_queries(DiscoverKind::Papers)
            .iter()
            .any(|q| q.contains("preprint"))
    );
    assert!(
        sources::discovery_queries(DiscoverKind::Repos)
            .iter()
            .any(|q| q.contains("Forgejo"))
    );
    assert!(
        sources::discovery_queries(DiscoverKind::All).len()
            > sources::discovery_queries(DiscoverKind::Repos).len()
    );
}

#[test]
fn parses_duckduckgo_html_as_low_confidence_informational_sources() {
    let html = r#"<a rel="nofollow" class="result__a" href="https://example.org/api">Example API docs</a>"#;
    let sources = sources::parse_duckduckgo_html(
        DiscoverKind::Papers,
        "scholarly metadata APIs",
        "https://duckduckgo.com/html/?q=x",
        html,
    );
    assert_eq!(sources.len(), 1);
    assert_eq!(sources[0].kind, "papers");
    assert_eq!(sources[0].source_type, "aggregator_api");
    assert_eq!(sources[0].confidence, "low");
    assert!(sources[0].evidence_snippets[0].contains("Example API docs"));
}
