use chrono::{DateTime, FixedOffset};
use serde::Deserialize;
use crate::{
common::{Message, PlaceValUnit},
fetch::impl_api,
};
#[derive(Clone, Debug, Deserialize)]
pub struct LightningData {
pub place: String,
#[serde(deserialize_with = "crate::internal::deserialize::deserialize_to_bool")]
pub occur: bool,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Lightning {
pub data: Vec<LightningData>,
pub start_time: DateTime<FixedOffset>,
pub end_time: DateTime<FixedOffset>,
}
#[derive(Clone, Debug, Deserialize)]
pub struct RainfallData {
pub place: String,
pub max: Option<f32>,
pub min: Option<f32>,
pub unit: String,
#[serde(rename = "main")]
#[serde(deserialize_with = "crate::internal::deserialize::deserialize_to_bool")]
pub maintenance: bool,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Rainfall {
pub data: Vec<RainfallData>,
pub start_time: DateTime<FixedOffset>,
pub end_time: DateTime<FixedOffset>,
}
#[derive(Clone, Debug, Deserialize)]
pub struct UVIndexData {
pub place: String,
pub value: f32,
pub desc: String,
pub message: Option<String>,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UVIndex {
pub data: Vec<UVIndexData>,
pub record_desc: String,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(untagged)]
pub enum UVIndexOrEmpty {
UVIndex(UVIndex),
Empty(String),
}
impl UVIndexOrEmpty {
#[must_use]
pub const fn is_empty(&self) -> bool {
matches!(self, Self::Empty(_))
}
#[must_use]
#[allow(clippy::missing_const_for_fn)]
pub fn uv_index(self) -> Option<UVIndex> {
match self {
#[allow(unused_variables)]
Self::Empty(x) => None,
Self::UVIndex(x) => Some(x),
}
}
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Temperature {
pub data: Vec<PlaceValUnit>,
pub record_time: DateTime<FixedOffset>,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Humidity {
pub data: Vec<PlaceValUnit>,
pub record_time: DateTime<FixedOffset>,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Icon {
pub icon: Vec<i32>,
#[serde(rename = "iconUpdateTime")]
pub update_time: DateTime<FixedOffset>,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Current {
pub lightning: Option<Lightning>,
pub rainfall: Rainfall,
#[serde(flatten)]
pub icon: Icon,
#[serde(rename = "uvindex")]
pub uv_index: UVIndexOrEmpty,
pub warning_message: Option<Message>,
pub rainstorm_reminder: Option<String>,
#[serde(rename = "specialWxTips")]
pub special_tips: Option<Message>,
pub tcmessage: Option<Message>,
pub mintemp_from00_to09: String,
pub rainfall_from00_to12: String,
pub rainfall_last_month: String,
pub rainfall_january_to_last_month: String,
pub temperature: Temperature,
pub humidity: Humidity,
pub update_time: DateTime<FixedOffset>,
}
impl_api!(Current, weather, rhrread);