use actix_web::{HttpMessage, HttpRequest};

#[derive(Debug, Clone)]
pub struct ResolvedAthenaClient(pub String);

#[derive(Debug, Clone, Copy)]
pub struct DisallowJdbcRouting;

/// Sets the resolved Athena client name in the request extensions, allowing it to be accessed later in the request handling process.
///
pub fn set_resolved_athena_client(req: &HttpRequest, client_name: String) {
    req.extensions_mut()
        .insert(ResolvedAthenaClient(client_name));
}

/// Retrieves the resolved Athena client name from the request extensions, if it has been set.  
///     
///
pub fn resolved_athena_client(req: &HttpRequest) -> Option<String> {
    req.extensions()
        .get::<ResolvedAthenaClient>()
        .map(|v| v.0.clone())
}

/// Sets a flag in the request extensions to indicate that JDBC routing should be disallowed for this request.
pub fn set_disallow_jdbc_routing(req: &HttpRequest) {
    req.extensions_mut().insert(DisallowJdbcRouting);
}

/// Checks if the `DisallowJdbcRouting` flag is set in the request extensions, indicating that JDBC routing should be disallowed for this request.
/// Returns `true` if JDBC routing should be disallowed, and `false` otherwise.
/// This function is used to determine whether to bypass JDBC routing logic for certain requests, based on the presence of the `DisallowJdbcRouting` marker in the request's extensions.
///
pub fn disallow_jdbc_routing(req: &HttpRequest) -> bool {
    req.extensions().get::<DisallowJdbcRouting>().is_some()
}
