//! Smoke test for the Vision OCR bridge. Reads an image path from
//! argv[1] (or `/tmp/car-vision-ocr-test.png` by default) and prints
//! the recognized observations.
//!
//! Run with: `cargo run -p car-vision --example ocr_smoke -- <path>`.

use std::path::PathBuf;

fn main() {
    let path: PathBuf = std::env::args()
        .nth(1)
        .unwrap_or_else(|| "/tmp/car-vision-ocr-test.png".to_string())
        .into();

    println!(
        "car_vision::is_available() = {}",
        car_vision::is_available()
    );
    println!("image path = {}", path.display());

    let config = car_vision::ocr::OcrConfig::default();
    match car_vision::ocr::recognize(&path, &config) {
        Ok(observations) => {
            println!("got {} observations", observations.len());
            for (i, o) in observations.iter().enumerate() {
                println!(
                    "  [{:>3}] {:.3} '{}' bbox=({:.3},{:.3},{:.3},{:.3})",
                    i, o.confidence, o.text, o.x, o.y, o.w, o.h
                );
            }
        }
        Err(e) => {
            eprintln!("error: {e}");
            std::process::exit(1);
        }
    }
}
