use actix_web::HttpRequest;
use actix_web::test::TestRequest;
use athena_rs::api::headers::{
    x_athena_client::x_athena_client, x_company_id::get_x_company_id,
    x_organization_id::get_x_organization_id, x_strip_nulls::get_x_strip_nulls,
    x_user_id::get_x_user_id,
};

#[actix_web::test]
async fn x_athena_client_returns_empty_when_missing() {
    let req: HttpRequest = TestRequest::default().to_http_request();
    assert_eq!(x_athena_client(&req), "");
}

#[actix_web::test]
async fn x_athena_client_returns_value_when_present() {
    let req: HttpRequest = TestRequest::default()
        .insert_header(("X-Athena-Client", "supabase"))
        .to_http_request();
    assert_eq!(x_athena_client(&req), "supabase");
}

#[actix_web::test]
async fn x_company_id_returns_none_when_missing() {
    let req = TestRequest::default().to_http_request();
    assert!(get_x_company_id(&req).is_none());
}

#[actix_web::test]
async fn x_company_id_returns_value_when_present() {
    let req = TestRequest::default()
        .insert_header(("X-Company-Id", "company-1"))
        .to_http_request();
    assert_eq!(get_x_company_id(&req).unwrap(), "company-1");
}

#[actix_web::test]
async fn x_organization_id_returns_none_when_missing() {
    let req: HttpRequest = TestRequest::default().to_http_request();
    assert!(get_x_organization_id(&req).is_none());
}

#[actix_web::test]
async fn x_organization_id_returns_value_when_present() {
    let req: HttpRequest = TestRequest::default()
        .insert_header(("X-Organization-Id", "org-xyz"))
        .to_http_request();
    assert_eq!(get_x_organization_id(&req).unwrap(), "org-xyz");
}

#[actix_web::test]
async fn x_strip_nulls_returns_none_when_missing() {
    let req: HttpRequest = TestRequest::default().to_http_request();
    assert!(get_x_strip_nulls(&req).is_none());
}

#[actix_web::test]
async fn x_strip_nulls_returns_value_when_present() {
    let req: HttpRequest = TestRequest::default()
        .insert_header(("X-Strip-Nulls", "true"))
        .to_http_request();
    assert_eq!(get_x_strip_nulls(&req).unwrap(), "true");
}

#[actix_web::test]
async fn x_user_id_returns_none_when_missing() {
    let req: HttpRequest = TestRequest::default().to_http_request();
    assert!(get_x_user_id(&req).is_none());
}

#[actix_web::test]
async fn x_user_id_returns_value_when_present() {
    let req: HttpRequest = TestRequest::default()
        .insert_header(("X-User-Id", "user-123"))
        .to_http_request();
    assert_eq!(get_x_user_id(&req).unwrap(), "user-123");
}
