use serde::Serialize;

#[derive(Debug, Clone, Copy, Serialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[allow(dead_code)]
pub enum Timezone {
    Utc,
    Stockholm,
}
pub use Timezone::*;

impl Timezone {
    pub const fn to_tz(self) -> chrono_tz::Tz
    where
        chrono_tz::Tz: Sized + Copy,
    {
        use chrono_tz::{Europe, UTC};
        match self {
            Utc => UTC,
            Stockholm => Europe::Stockholm,
        }
    }
}

#[cfg(test)]
impl Timezone {
    pub fn dt(
        &self,
        year: i32,
        month: u32,
        day: u32,
        hour: u32,
        minute: u32,
        second: u32,
    ) -> chrono::DateTime<chrono_tz::Tz> {
        use chrono::TimeZone;
        let tz = self.to_tz();
        tz.with_ymd_and_hms(year, month, day, hour, minute, second)
            .unwrap()
    }
}

impl From<Timezone> for chrono_tz::Tz {
    fn from(timezone: Timezone) -> Self {
        timezone.to_tz()
    }
}
