use chrono::NaiveDate;
use rmcp::model::ErrorCode;

use super::*;

#[test]
fn render_chain_keeps_source_context() {
    let error = ToolError::BlobRead {
        path: "/store/faa-nasr/x.acnav".to_owned(),
        cause: std::io::Error::new(std::io::ErrorKind::PermissionDenied, "permission denied"),
    };
    let text = render_chain(&error);
    assert!(text.contains("/store/faa-nasr/x.acnav"));
    assert!(text.contains("permission denied"));
}

#[test]
fn invalid_params_map_to_the_protocol_code() {
    let data = ErrorData::from(ToolError::InvalidParam {
        message: "radius_nm must be finite".to_owned(),
    });
    assert_eq!(data.code, ErrorCode::INVALID_PARAMS);
    assert!(data.message.contains("radius_nm"));
}

#[test]
fn empty_store_error_tells_the_agent_how_to_recover() {
    let data = ErrorData::from(ToolError::StoreEmpty {
        store: "/home/pilot/.aerocontext/navdata".to_owned(),
        date: NaiveDate::from_ymd_opt(2026, 6, 12).unwrap(),
    });
    assert_eq!(data.code, ErrorCode::INTERNAL_ERROR);
    assert!(data.message.contains("navdata_sync"));
    assert!(data.message.contains("aerocontext-navdata sync"));
}
