use crate::service::{ProvidedArgument, RequiredArgument};
use libtad_models::holidays::HolidayType;
use serde::Serialize;
macro_rules! return_type {
($self:ident) => {
HolidaysRequest {
country: $self.country,
year: $self.year,
lang: $self.lang,
types: $self.types,
tz: $self.tz,
verbosetime: $self.verbosetime,
_a: Default::default(),
_b: Default::default(),
}
};
}
#[derive(Default, Serialize)]
pub struct HolidaysRequest<A = ProvidedArgument, B = ProvidedArgument> {
country: Vec<String>,
year: u16,
lang: Option<Vec<String>>,
types: Option<Vec<HolidayType>>,
tz: Option<u8>,
verbosetime: Option<u8>,
_a: std::marker::PhantomData<A>,
_b: std::marker::PhantomData<B>,
}
impl HolidaysRequest {
pub fn new() -> HolidaysRequest<RequiredArgument, RequiredArgument> {
Default::default()
}
}
impl<A, B> HolidaysRequest<A, B> {
pub fn with_country(
mut self,
country: impl Into<String>,
) -> HolidaysRequest<ProvidedArgument, B> {
self.country.push(country.into());
return_type!(self)
}
pub fn set_year(mut self, year: u16) -> HolidaysRequest<A, ProvidedArgument> {
self.year = year;
return_type!(self)
}
pub fn with_lang(mut self, lang: impl Into<String>) -> Self {
if let Some(ref mut langs) = self.lang {
langs.push(lang.into());
} else {
self.lang.insert(vec![lang.into()]);
}
self
}
pub fn with_type(mut self, holiday_type: HolidayType) -> Self {
if let Some(ref mut types) = self.types {
types.push(holiday_type);
} else {
self.types.insert(vec![holiday_type]);
}
self
}
pub fn set_tz(mut self, enable: bool) -> Self {
self.tz.insert(enable.into());
self
}
pub fn set_verbose_time(mut self, enable: bool) -> Self {
self.verbosetime.insert(enable.into());
self
}
}