#[cfg(feature = "url-filtering")]
use super::UrlFilter;
#[cfg(feature = "url-priority")]
use super::UrlPriority;
use std::collections::HashSet;
use url::Url;

pub type PageCrawledCallback = Box<dyn Fn(&Url, &str, usize, usize, usize) + Send + Sync>;

/// Runtime options for [`super::Crawler`].
pub struct CrawlerConfig {
    /// First URL to crawl. `None` makes [`super::Crawler::crawl`] fail with `NoStartUrl`.
    pub start_url: Option<Url>,
    /// Maximum number of accepted URLs before crawling stops.
    pub max_pages: usize,
    /// Delay between successful page fetches.
    pub delay_ms: u64,
    /// Maximum number of in-flight fetches during crawling.
    pub max_concurrency: usize,
    /// User agent sent with HTTP requests.
    pub user_agent: String,
    #[cfg(feature = "url-filtering")]
    /// Optional URL predicate used before queueing links.
    pub url_filter: Option<UrlFilter>,
    #[cfg(feature = "url-priority")]
    /// Optional URL score used to prioritize queued links. Higher scores are
    /// crawled sooner.
    pub url_priority: Option<UrlPriority>,
    /// Optional callback invoked after each successful page fetch.
    pub on_page_crawled: Option<PageCrawledCallback>,
    /// Seed the visited set before crawling — URLs here are skipped on resume.
    pub initial_visited: HashSet<Url>,
}
impl Default for CrawlerConfig {
    fn default() -> Self {
        Self {
            start_url: None,
            max_pages: 1000,
            delay_ms: 500,
            max_concurrency: 1,
            user_agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36".to_string(),
            #[cfg(feature = "url-filtering")]
            url_filter: None,
            #[cfg(feature = "url-priority")]
            url_priority: None,
            on_page_crawled: None,
            initial_visited: HashSet::new(),
        }
    }
}
