Documentation
use crate::http;
use serde::Serialize;

pub mod absences;
pub mod announced_tests;
pub mod classes;
pub mod evaluations;
pub mod lessons;
pub mod messages;
pub mod schools;
pub mod token;
pub mod user_info;

// uri
// method
// query
// headers
pub trait Endpoint: std::fmt::Debug {
    type Args;

    /// if differs from `BASE_URL`
    fn base_url(args: impl AsRef<str>) -> String {
        base::school_base(args.as_ref())
    }

    /// after `BASE_URL`
    fn path(args: &Self::Args) -> String;

    fn method() -> http::Method {
        http::Method::GET
    }

    fn query(_input: Self::Args) -> Vec<(&'static str, String)> {
        Vec::new()
    }

    /// Gather the request headers to set.
    fn headers(_input: &impl Serialize) -> crate::Res<Option<http::HeaderMap>> {
        Ok(None)
    }

    /// when was `self` fetched
    fn when(&self) -> Option<crate::LDateTime> {
        None
    }
}
fn opt_irval_to_query(optirval: crate::OptIrval) -> Vec<(&'static str, String)> {
    let mut q = vec![];
    if let Some(from) = optirval.0 {
        let from = from.and_hms_opt(0, 0, 0).unwrap().to_string();
        q.push(("datumTol", from));
    }
    if let Some(to) = optirval.1 {
        let to = to.and_hms_opt(23, 59, 59).unwrap().to_string();
        q.push(("datumIg", to));
    }
    q
}
pub mod base {
    pub const IDP: &str = "https://idp.e-kreta.hu";
    pub const ADMIN: &str = "https://eugyintezes.e-kreta.hu";

    pub fn school_base(school_id: impl AsRef<str>) -> String {
        format!("https://{}.e-kreta.hu", school_id.as_ref())
    }
}