use doku::Document;
use serde::{Deserialize, Serialize};
use std::{
cell::OnceCell,
ffi::OsStr,
fmt::{self},
};
use super::types::config_color::ConfigColor;
#[derive(Debug, Deserialize, Serialize, Document, PartialEq, Eq)]
pub struct CalendarSourceConfig {
#[doku(
example = "calendars/mycalendar_file.ics",
example = "https://example.com/my/calendar/url/ical/"
)]
pub source: String,
pub name: String,
pub title: Option<String>,
pub(crate) color: ConfigColor,
#[serde(skip)]
pub(crate) adjusted_color: OnceCell<String>,
pub cookies: Option<Vec<String>>,
}
impl fmt::Display for CalendarSourceConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.source,)
}
}
impl<'a> From<&'a CalendarSourceConfig> for &'a str {
fn from(value: &'a CalendarSourceConfig) -> &str {
&value.source
}
}
impl From<&CalendarSourceConfig> for String {
fn from(value: &CalendarSourceConfig) -> Self {
value.source.clone()
}
}
impl AsRef<OsStr> for CalendarSourceConfig {
fn as_ref(&self) -> &std::ffi::OsStr {
OsStr::new(&self.source)
}
}