use super::super::types::{
DataNotFoundError, NeaWeatherSubApi, RateLimitError, WeatherSubApiInvalidParamsError,
WeatherSubApiResponse,
};
#[derive(Debug, Clone, PartialEq)]
pub struct WeatherSubApiInput {
pub api: NeaWeatherSubApi,
pub date: Option<satay_runtime::Date>,
pub pagination_token: Option<String>,
pub x_api_key: Option<String>,
}
impl WeatherSubApiInput {
pub fn new(api: NeaWeatherSubApi) -> Self {
Self {
api,
date: None,
pagination_token: None,
x_api_key: None,
}
}
pub fn date(mut self, date: satay_runtime::Date) -> Self {
self.date = Some(date);
self
}
pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
self.pagination_token = Some(pagination_token.into());
self
}
pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
self.x_api_key = Some(x_api_key.into());
self
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum WeatherSubApiOperationResponse {
Ok(WeatherSubApiResponse),
BadRequest(WeatherSubApiInvalidParamsError),
NotFound(DataNotFoundError),
Status429(RateLimitError),
UnexpectedStatus(http::StatusCode, Vec<u8>),
}
pub fn weather_sub_api_parts(
input: WeatherSubApiInput,
) -> Result<satay_runtime::RequestParts<()>, satay_runtime::Error> {
let mut uri = String::with_capacity(8);
uri.push_str("/weather");
let mut first_query = true;
satay_runtime::append_query_pair(&mut uri, &mut first_query, "api", input.api.as_ref());
if let Some(value) = &input.date {
satay_runtime::append_query_pair(
&mut uri,
&mut first_query,
"date",
&satay_runtime::format_date(value),
);
}
if let Some(value) = &input.pagination_token {
satay_runtime::append_query_pair(
&mut uri,
&mut first_query,
"paginationToken",
value.as_str(),
);
}
let mut headers = http::HeaderMap::new();
if let Some(value) = &input.x_api_key {
satay_runtime::insert_header(&mut headers, "x-api-key", value.as_str())?;
}
Ok(satay_runtime::RequestParts {
method: http::Method::GET,
uri,
headers,
body: (),
})
}