use crate::Client;
use crate::util::urlish;
#[derive(Clone, Copy, Debug)]
pub struct OrgScope;
#[derive(Clone, Copy, Debug)]
pub struct InboxScope<'a>(pub &'a str);
#[derive(Clone, Copy, Debug)]
pub struct PodScope<'a>(pub &'a str);
pub trait Scope {
fn base(&self) -> String;
}
impl Scope for OrgScope {
fn base(&self) -> String {
"/v0".to_string()
}
}
impl Scope for InboxScope<'_> {
fn base(&self) -> String {
format!("/v0/inboxes/{}", urlish(self.0))
}
}
impl Scope for PodScope<'_> {
fn base(&self) -> String {
format!("/v0/pods/{}", urlish(self.0))
}
}
#[derive(Clone, Copy, Debug)]
pub struct Scoped<'c, S> {
pub(crate) client: &'c Client,
pub(crate) scope: S,
}
impl<'c, S: Scope> Scoped<'c, S> {
pub(crate) fn base(&self) -> String {
self.scope.base()
}
}
pub trait Threads: Scope {}
impl Threads for OrgScope {}
impl Threads for InboxScope<'_> {}
impl Threads for PodScope<'_> {}
pub trait Drafts: Scope {}
impl Drafts for OrgScope {}
impl Drafts for InboxScope<'_> {}
impl Drafts for PodScope<'_> {}
pub trait Webhooks: Scope {}
impl Webhooks for OrgScope {}
impl Webhooks for InboxScope<'_> {}
impl Webhooks for PodScope<'_> {}
pub trait Lists: Scope {}
impl Lists for OrgScope {}
impl Lists for InboxScope<'_> {}
impl Lists for PodScope<'_> {}
pub trait Metrics: Scope {}
impl Metrics for OrgScope {}
impl Metrics for InboxScope<'_> {}
impl Metrics for PodScope<'_> {}
pub trait ApiKeys: Scope {}
impl ApiKeys for OrgScope {}
impl ApiKeys for InboxScope<'_> {}
impl ApiKeys for PodScope<'_> {}
pub trait Domains: Scope {}
impl Domains for OrgScope {}
impl Domains for PodScope<'_> {}
pub trait Inboxes: Scope {}
impl Inboxes for OrgScope {}
impl Inboxes for PodScope<'_> {}
impl Client {
pub fn org(&self) -> Scoped<'_, OrgScope> {
Scoped {
client: self,
scope: OrgScope,
}
}
pub fn inbox<'a>(&'a self, inbox_id: &'a str) -> Scoped<'a, InboxScope<'a>> {
Scoped {
client: self,
scope: InboxScope(inbox_id),
}
}
pub fn pod<'a>(&'a self, pod_id: &'a str) -> Scoped<'a, PodScope<'a>> {
Scoped {
client: self,
scope: PodScope(pod_id),
}
}
}