use std::marker::PhantomData;
use http::HeaderMap;
use crate::xet_session::XetSession;
#[derive(Default)]
pub(super) struct AuthOptions {
pub(super) endpoint: Option<String>,
pub(super) custom_headers: Option<HeaderMap>,
pub(super) token_info: Option<(String, u64)>,
pub(super) token_refresh: Option<(String, HeaderMap)>,
}
pub struct AuthGroupBuilder<G> {
pub(super) session: XetSession,
pub(super) auth_options: AuthOptions,
_marker: PhantomData<G>,
}
impl<G> AuthGroupBuilder<G> {
pub(super) fn new(session: XetSession) -> Self {
Self {
session,
auth_options: Default::default(),
_marker: PhantomData,
}
}
pub fn with_endpoint(self, endpoint: impl Into<String>) -> Self {
Self {
auth_options: AuthOptions {
endpoint: Some(endpoint.into()),
..self.auth_options
},
..self
}
}
pub fn with_custom_headers(self, headers: HeaderMap) -> Self {
Self {
auth_options: AuthOptions {
custom_headers: Some(headers),
..self.auth_options
},
..self
}
}
pub fn with_token_info(self, token: impl Into<String>, expiry: u64) -> Self {
Self {
auth_options: AuthOptions {
token_info: Some((token.into(), expiry)),
..self.auth_options
},
..self
}
}
pub fn with_token_refresh_url(self, url: impl Into<String>, headers: HeaderMap) -> Self {
Self {
auth_options: AuthOptions {
token_refresh: Some((url.into(), headers)),
..self.auth_options
},
..self
}
}
}