osdm-sys 0.1.0-alpha.2

Specifications for the OSDM API standard. The OSDM specification supports two modes of operation: Retailer Mode and Distributor Mode. The API works identically in both modes, except that in distributor mode the API also returns fare information. The following resources are key to get started: - [Processes](https://osdm.io/spec/processes/) - [Models](https://osdm.io/spec/models/) - [Getting started](https://osdm.io/spec/getting-started/)
Documentation
/*
 * UIC 90918-10 - OSDM
 *
 * Specifications for the OSDM API standard. The OSDM specification supports two modes of operation: Retailer Mode and Distributor Mode. The API works identically in both modes, except that in distributor mode the API also returns fare information.  The following resources are key to get started:    -  [Processes](https://osdm.io/spec/processes/)   -  [Models](https://osdm.io/spec/models/)   -  [Getting started](https://osdm.io/spec/getting-started/) 
 *
 * The version of the OpenAPI document: 3.7.0
 * Contact: osdm@uic.org
 * Generated by: https://openapi-generator.tech
 */


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


/// struct for typed errors of method [`delete_booking_booked_offers_id`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteBookingBookedOffersIdError {
    Status400(models::Problem),
    Status401(models::Problem),
    Status403(models::Problem),
    Status404(models::Problem),
    Status406(models::Problem),
    Status409(models::Problem),
    Status415(models::Problem),
    Status500(models::Problem),
    Status501(models::Problem),
    Status503(models::Problem),
    DefaultResponse(models::Problem),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`delete_booking_booked_offers_id_passenger_id`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteBookingBookedOffersIdPassengerIdError {
    Status400(models::Problem),
    Status401(models::Problem),
    Status403(models::Problem),
    Status404(models::Problem),
    Status406(models::Problem),
    Status409(models::Problem),
    Status415(models::Problem),
    Status500(models::Problem),
    Status501(models::Problem),
    Status503(models::Problem),
    DefaultResponse(models::Problem),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_booking_booked_offers_id`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetBookingBookedOffersIdError {
    Status400(models::Problem),
    Status401(models::Problem),
    Status403(models::Problem),
    Status404(models::Problem),
    Status406(models::Problem),
    Status415(models::Problem),
    Status500(models::Problem),
    Status501(models::Problem),
    Status503(models::Problem),
    DefaultResponse(models::Problem),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`post_booking_booked_offers`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PostBookingBookedOffersError {
    Status400(models::Problem),
    Status401(models::Problem),
    Status403(models::Problem),
    Status404(models::Problem),
    Status406(models::Problem),
    Status415(models::Problem),
    Status500(models::Problem),
    Status501(models::Problem),
    Status503(models::Problem),
    DefaultResponse(models::Problem),
    UnknownValue(serde_json::Value),
}


pub async fn delete_booking_booked_offers_id(configuration: &configuration::Configuration, booking_id: &str, booked_offer_id: &str, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>) -> Result<(), Error<DeleteBookingBookedOffersIdError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_booking_id = booking_id;
    let p_path_booked_offer_id = booked_offer_id;
    let p_header_requestor = requestor;
    let p_header_accept_language = accept_language;
    let p_header_traceparent = traceparent;
    let p_header_tracestate = tracestate;

    let uri_str = format!("{}/bookings/{bookingId}/booked-offers/{bookedOfferId}", configuration.base_path, bookingId=crate::apis::urlencode(p_path_booking_id), bookedOfferId=crate::apis::urlencode(p_path_booked_offer_id));
    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &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_requestor {
        req_builder = req_builder.header("Requestor", param_value.to_string());
    }
    if let Some(param_value) = p_header_accept_language {
        req_builder = req_builder.header("Accept-Language", param_value.to_string());
    }
    if let Some(param_value) = p_header_traceparent {
        req_builder = req_builder.header("traceparent", param_value.to_string());
    }
    if let Some(param_value) = p_header_tracestate {
        req_builder = req_builder.header("tracestate", param_value.to_string());
    }
    if let Some(ref token) = configuration.oauth_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

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

    let status = resp.status();

    if !status.is_client_error() && !status.is_server_error() {
        Ok(())
    } else {
        let content = resp.text().await?;
        let entity: Option<DeleteBookingBookedOffersIdError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Deletes all booked offer parts of the passenger only if this valid from a tariff point of view. This implies that the offer part are sufficiently partitioned and no repricing is needed. 
pub async fn delete_booking_booked_offers_id_passenger_id(configuration: &configuration::Configuration, booking_id: &str, offer_id: &str, passenger_id: &str, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>) -> Result<(), Error<DeleteBookingBookedOffersIdPassengerIdError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_booking_id = booking_id;
    let p_path_offer_id = offer_id;
    let p_path_passenger_id = passenger_id;
    let p_header_requestor = requestor;
    let p_header_accept_language = accept_language;
    let p_header_traceparent = traceparent;
    let p_header_tracestate = tracestate;

    let uri_str = format!("{}/bookings/{bookingId}/booked-offers/{offerId}/passengers/{passengerId}", configuration.base_path, bookingId=crate::apis::urlencode(p_path_booking_id), offerId=crate::apis::urlencode(p_path_offer_id), passengerId=crate::apis::urlencode(p_path_passenger_id));
    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &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_requestor {
        req_builder = req_builder.header("Requestor", param_value.to_string());
    }
    if let Some(param_value) = p_header_accept_language {
        req_builder = req_builder.header("Accept-Language", param_value.to_string());
    }
    if let Some(param_value) = p_header_traceparent {
        req_builder = req_builder.header("traceparent", param_value.to_string());
    }
    if let Some(param_value) = p_header_tracestate {
        req_builder = req_builder.header("tracestate", param_value.to_string());
    }
    if let Some(ref token) = configuration.oauth_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

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

    let status = resp.status();

    if !status.is_client_error() && !status.is_server_error() {
        Ok(())
    } else {
        let content = resp.text().await?;
        let entity: Option<DeleteBookingBookedOffersIdPassengerIdError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

pub async fn get_booking_booked_offers_id(configuration: &configuration::Configuration, booking_id: &str, booked_offer_id: &str, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, x_accept_namespace: Option<&str>) -> Result<models::BookedOfferResponse, Error<GetBookingBookedOffersIdError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_booking_id = booking_id;
    let p_path_booked_offer_id = booked_offer_id;
    let p_header_requestor = requestor;
    let p_header_accept_language = accept_language;
    let p_header_traceparent = traceparent;
    let p_header_tracestate = tracestate;
    let p_header_x_accept_namespace = x_accept_namespace;

    let uri_str = format!("{}/bookings/{bookingId}/booked-offers/{bookedOfferId}", configuration.base_path, bookingId=crate::apis::urlencode(p_path_booking_id), bookedOfferId=crate::apis::urlencode(p_path_booked_offer_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(param_value) = p_header_requestor {
        req_builder = req_builder.header("Requestor", param_value.to_string());
    }
    if let Some(param_value) = p_header_accept_language {
        req_builder = req_builder.header("Accept-Language", param_value.to_string());
    }
    if let Some(param_value) = p_header_traceparent {
        req_builder = req_builder.header("traceparent", param_value.to_string());
    }
    if let Some(param_value) = p_header_tracestate {
        req_builder = req_builder.header("tracestate", param_value.to_string());
    }
    if let Some(param_value) = p_header_x_accept_namespace {
        req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
    }
    if let Some(ref token) = configuration.oauth_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    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::BookedOfferResponse`"))),
            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::BookedOfferResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetBookingBookedOffersIdError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

pub async fn post_booking_booked_offers(configuration: &configuration::Configuration, booking_id: &str, booked_offer_request: models::BookedOfferRequest, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, idempotency_key: Option<&str>, x_accept_namespace: Option<&str>) -> Result<models::BookedOfferResponse, Error<PostBookingBookedOffersError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_booking_id = booking_id;
    let p_body_booked_offer_request = booked_offer_request;
    let p_header_requestor = requestor;
    let p_header_accept_language = accept_language;
    let p_header_traceparent = traceparent;
    let p_header_tracestate = tracestate;
    let p_header_idempotency_key = idempotency_key;
    let p_header_x_accept_namespace = x_accept_namespace;

    let uri_str = format!("{}/bookings/{bookingId}/booked-offers", configuration.base_path, bookingId=crate::apis::urlencode(p_path_booking_id));
    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_requestor {
        req_builder = req_builder.header("Requestor", param_value.to_string());
    }
    if let Some(param_value) = p_header_accept_language {
        req_builder = req_builder.header("Accept-Language", param_value.to_string());
    }
    if let Some(param_value) = p_header_traceparent {
        req_builder = req_builder.header("traceparent", param_value.to_string());
    }
    if let Some(param_value) = p_header_tracestate {
        req_builder = req_builder.header("tracestate", param_value.to_string());
    }
    if let Some(param_value) = p_header_idempotency_key {
        req_builder = req_builder.header("Idempotency-Key", param_value.to_string());
    }
    if let Some(param_value) = p_header_x_accept_namespace {
        req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
    }
    if let Some(ref token) = configuration.oauth_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };
    req_builder = req_builder.json(&p_body_booked_offer_request);

    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::BookedOfferResponse`"))),
            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::BookedOfferResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<PostBookingBookedOffersError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}