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

use super::super::types::{DataNotFoundError, InvalidParamsError, RateLimitError, UvResponse};
use super::parts::{UvInput, UvOperationResponse, uv_parts};
/// <https://api-open.data.gov.sg/v2/real-time/api/uv>
///
/// - Updated between 7 AM and 7 PM everyday
///
/// - The UV index value is averaged over the preceding hour
///
/// - Filter for a specific date by providing `date` in query parameter (YYYY-MM-DD).
///
/// - example: `?date=2024-07-16`
///
/// - If `date` is not provided in query parameter, API will return the latest reading
///
/// - Unit of measure for readings is `Ultraviolet Index`
pub fn encode_uv(input: UvInput) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
    let parts = uv_parts(input)?;
    satay_runtime::into_empty_request(parts)
}
pub fn decode_uv_response<B: AsRef<[u8]>>(
    response: satay_runtime::ResponseParts<B>,
) -> Result<UvOperationResponse, satay_runtime::Error> {
    let status = response.status;
    match status.as_u16() {
        200 => {
            let body = response.body;
            let value = satay_runtime::from_json_slice::<UvResponse>(body.as_ref())?;
            Ok(UvOperationResponse::Ok(value))
        }
        400 => {
            let body = response.body;
            let value = satay_runtime::from_json_slice::<InvalidParamsError>(body.as_ref())?;
            Ok(UvOperationResponse::BadRequest(value))
        }
        404 => {
            let body = response.body;
            let value = satay_runtime::from_json_slice::<DataNotFoundError>(body.as_ref())?;
            Ok(UvOperationResponse::NotFound(value))
        }
        429 => {
            let body = response.body;
            let value = satay_runtime::from_json_slice::<RateLimitError>(body.as_ref())?;
            Ok(UvOperationResponse::Status429(value))
        }
        _ => {
            let body = response.body;
            Ok(UvOperationResponse::UnexpectedStatus(
                status,
                body.as_ref().to_vec(),
            ))
        }
    }
}
