//! @generated by satay. Do not edit by hand.

use super::super::types::{
    DataNotFoundError, InvalidParamsError, RateLimitError, TwentyFourHrForecastResponse,
};
use super::parts::{
    TwentyFourHrForecastInput, TwentyFourHrForecastOperationResponse, twenty_four_hr_forecast_parts,
};
/// <https://api-open.data.gov.sg/v2/real-time/api/twenty-four-hr-forecast>
///
/// - Updated multiple times throughout the day
///
/// - Filter for specific date or date-time by providing `date` in query parameter (YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS).
///
/// - example: `?date=2024-07-16` or `?date=2024-07-16T23:59:00`
///
/// - Forecasts are valid for twenty four hours, for example, the validity period of the forecast at 1st Jan 1pm is from 1st Jan 1pm to 2nd Jan 1pm
///
/// - If `date` is not provided in query parameter, API will return the latest reading
pub fn encode_twenty_four_hr_forecast(
    input: TwentyFourHrForecastInput,
) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
    let parts = twenty_four_hr_forecast_parts(input)?;
    satay_runtime::into_empty_request(parts)
}
pub fn decode_twenty_four_hr_forecast_response<B: AsRef<[u8]>>(
    response: satay_runtime::ResponseParts<B>,
) -> Result<TwentyFourHrForecastOperationResponse, satay_runtime::Error> {
    let status = response.status;
    match status.as_u16() {
        200 => {
            let body = response.body;
            let value =
                satay_runtime::from_json_slice::<TwentyFourHrForecastResponse>(body.as_ref())?;
            Ok(TwentyFourHrForecastOperationResponse::Ok(value))
        }
        400 => {
            let body = response.body;
            let value = satay_runtime::from_json_slice::<InvalidParamsError>(body.as_ref())?;
            Ok(TwentyFourHrForecastOperationResponse::BadRequest(value))
        }
        404 => {
            let body = response.body;
            let value = satay_runtime::from_json_slice::<DataNotFoundError>(body.as_ref())?;
            Ok(TwentyFourHrForecastOperationResponse::NotFound(value))
        }
        429 => {
            let body = response.body;
            let value = satay_runtime::from_json_slice::<RateLimitError>(body.as_ref())?;
            Ok(TwentyFourHrForecastOperationResponse::Status429(value))
        }
        _ => {
            let body = response.body;
            Ok(TwentyFourHrForecastOperationResponse::UnexpectedStatus(
                status,
                body.as_ref().to_vec(),
            ))
        }
    }
}
