//! Repository scanners. Deterministic surface classification by path and filename.
//!
//! Walks a target directory, hashes every file with SHA-256, and assigns
//! each one a `SourceClass` taxonomy bucket (e.g. `ProjectAdr`,
//! `EngineeringDoctrinePrinciple`, `ProjectAgentFile`, `BlockedSurface`).
//! Classification is **content-agnostic by design** — it never reads prose
//! to decide what something is, only path and filename.
//!
//! Block rules cover runtime exhaust (`.cordance/`, `.git/`, `.claude/cache/`,
//! `node_modules/`, `target/`, …), secret/credential filenames (`id_rsa`,
//! `.env`, `secrets.json`, `Credentials.*`), and OS junk (`.DS_Store`,
//! `Thumbs.db`). Case folding keeps `SECRET-FOO.TXT` blocked alongside
//! `secret-foo.txt` on default-case-insensitive NTFS / APFS.
//!
//! # Golden path
//!
//! ```no_run
//! use camino::Utf8PathBuf;
//!
//! let target = Utf8PathBuf::from(".");
//! let sources = cordance_scan::scan_repo(&target).expect("scan succeeds");
//!
//! for record in &sources {
//!     if record.blocked {
//!         eprintln!(
//!             "blocked: {} ({})",
//!             record.path,
//!             record.blocked_reason.as_deref().unwrap_or("?"),
//!         );
//!     } else {
//!         println!(
//!             "{:?}: {} ({} bytes)",
//!             record.class, record.path, record.size_bytes,
//!         );
//!     }
//! }
//! ```

#![forbid(unsafe_code)]
#![deny(clippy::unwrap_used, clippy::expect_used)]
#![cfg_attr(test, allow(clippy::expect_used, clippy::unwrap_used))]

use camino::Utf8PathBuf;
use cordance_core::source::{SourceClass, SourceRecord};

pub mod blocked;
pub mod classifier;
pub mod hasher;
pub mod walker;

#[derive(Debug, thiserror::Error)]
pub enum ScanError {
    #[error("io error reading {path}: {source}")]
    Io {
        path: Utf8PathBuf,
        #[source]
        source: std::io::Error,
    },
    #[error("path is not valid utf-8: {0}")]
    NonUtf8Path(String),
}

/// Top-level scan entrypoint. Delegates to `walker::walk`.
#[allow(clippy::missing_errors_doc)]
pub fn scan_repo(root: &Utf8PathBuf) -> Result<Vec<SourceRecord>, ScanError> {
    walker::walk(root)
}

/// Classify a path using only its repo-relative location. No content reads.
#[must_use]
pub fn classify_by_path(rel_path: &str) -> SourceClass {
    classifier::classify(rel_path)
}
