autogen-stedi 0.3.2

Auto-generated, strongly-typed Rust client for the Stedi APIs
Documentation
/*
 * Stedi Manager
 *
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: 2024-04-01
 * Contact: healthcare@stedi.com
 * Generated by: https://openapi-generator.tech
 */


use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::manager::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};


/// struct for typed errors of method [`batch_eligibility_checks`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum BatchEligibilityChecksError {
    Status400(models::ValidationExceptionResponseContent),
    Status401(models::UnauthorizedExceptionResponseContent),
    Status403(models::AccessDeniedExceptionResponseContent),
    Status404(models::ResourceNotFoundExceptionResponseContent),
    Status409(models::ResourceConflictExceptionResponseContent),
    Status500(models::InternalFailureExceptionResponseContent),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`batch_eligibility_polling`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum BatchEligibilityPollingError {
    Status400(models::ValidationExceptionResponseContent),
    Status401(models::UnauthorizedExceptionResponseContent),
    Status403(models::AccessDeniedExceptionResponseContent),
    Status404(models::ResourceNotFoundExceptionResponseContent),
    Status500(models::InternalFailureExceptionResponseContent),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_batch`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetBatchError {
    Status400(models::ValidationExceptionResponseContent),
    Status401(models::UnauthorizedExceptionResponseContent),
    Status403(models::AccessDeniedExceptionResponseContent),
    Status404(models::ResourceNotFoundExceptionResponseContent),
    Status500(models::InternalFailureExceptionResponseContent),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_batch_items`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetBatchItemsError {
    Status400(models::ValidationExceptionResponseContent),
    Status401(models::UnauthorizedExceptionResponseContent),
    Status403(models::AccessDeniedExceptionResponseContent),
    Status404(models::ResourceNotFoundExceptionResponseContent),
    Status500(models::InternalFailureExceptionResponseContent),
    UnknownValue(serde_json::Value),
}


/// Submit multiple eligibility checks for Stedi to process asynchronously
pub async fn batch_eligibility_checks(configuration: &configuration::Configuration, batch_eligibility_checks_request_content: models::BatchEligibilityChecksRequestContent, x_forwarded_for: Option<&str>) -> Result<models::BatchEligibilityChecksResponseContent, Error<BatchEligibilityChecksError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_body_batch_eligibility_checks_request_content = batch_eligibility_checks_request_content;
    let p_header_x_forwarded_for = x_forwarded_for;

    let uri_str = format!("{}/eligibility-manager/batch-eligibility", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(param_value) = p_header_x_forwarded_for {
        req_builder = req_builder.header("X-Forwarded-For", param_value.to_string());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("Authorization", value);
    };
    req_builder = req_builder.json(&p_body_batch_eligibility_checks_request_content);

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BatchEligibilityChecksResponseContent`"))),
            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BatchEligibilityChecksResponseContent`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<BatchEligibilityChecksError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Retrieve batch eligibility check results
pub async fn batch_eligibility_polling(configuration: &configuration::Configuration, page_size: Option<i32>, page_token: Option<&str>, batch_id: Option<&str>, start_date_time: Option<chrono::DateTime<chrono::FixedOffset>>) -> Result<models::BatchEligibilityPollingResponseContent, Error<BatchEligibilityPollingError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_query_page_size = page_size;
    let p_query_page_token = page_token;
    let p_query_batch_id = batch_id;
    let p_query_start_date_time = start_date_time;

    let uri_str = format!("{}/eligibility-manager/polling/batch-eligibility", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_page_size {
        req_builder = req_builder.query(&[("pageSize", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_page_token {
        req_builder = req_builder.query(&[("pageToken", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_batch_id {
        req_builder = req_builder.query(&[("batchId", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_start_date_time {
        req_builder = req_builder.query(&[("startDateTime", &param_value.to_rfc3339_opts(chrono::SecondsFormat::Secs, true))]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("Authorization", value);
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BatchEligibilityPollingResponseContent`"))),
            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BatchEligibilityPollingResponseContent`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<BatchEligibilityPollingError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Retrieve the status of an eligibility check batch submitted through the API or CSV upload
pub async fn get_batch(configuration: &configuration::Configuration, batch_id: &str) -> Result<models::GetBatchResponseContent, Error<GetBatchError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_batch_id = batch_id;

    let uri_str = format!("{}/eligibility-manager/batch/{batchId}", configuration.base_path, batchId=crate::manager::apis::urlencode(p_path_batch_id));
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("Authorization", value);
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetBatchResponseContent`"))),
            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetBatchResponseContent`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetBatchError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Retrieve status information for all eligibility checks within a batch, regardless of processing status
pub async fn get_batch_items(configuration: &configuration::Configuration, batch_id: &str, page_size: Option<i32>, page_token: Option<&str>, state: Option<Vec<models::BatchItemState>>, eligibility_check_result: Option<Vec<models::EligibilityCheckResult>>) -> Result<models::GetBatchItemsResponseContent, Error<GetBatchItemsError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_batch_id = batch_id;
    let p_query_page_size = page_size;
    let p_query_page_token = page_token;
    let p_query_state = state;
    let p_query_eligibility_check_result = eligibility_check_result;

    let uri_str = format!("{}/eligibility-manager/batch/{batchId}/items", configuration.base_path, batchId=crate::manager::apis::urlencode(p_path_batch_id));
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_page_size {
        req_builder = req_builder.query(&[("pageSize", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_page_token {
        req_builder = req_builder.query(&[("pageToken", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_state {
        req_builder = match "multi" {
            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("state".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
            _ => req_builder.query(&[("state", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
        };
    }
    if let Some(ref param_value) = p_query_eligibility_check_result {
        req_builder = match "multi" {
            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("eligibilityCheckResult".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
            _ => req_builder.query(&[("eligibilityCheckResult", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
        };
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("Authorization", value);
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetBatchItemsResponseContent`"))),
            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetBatchItemsResponseContent`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetBatchItemsError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}