use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(transparent)]
pub struct JwtScope(pub String);
impl JwtScope {
pub const DEVICES_LIST: &'static str = "devices:list";
pub const DEVICES_DELETE: &'static str = "devices:delete";
pub const INBOX_LIST: &'static str = "inbox:list";
pub const INBOX_REFRESH: &'static str = "inbox:refresh";
pub const LOGS_READ: &'static str = "logs:read";
pub const MESSAGES_CANCEL: &'static str = "messages:cancel";
pub const MESSAGES_SEND: &'static str = "messages:send";
pub const MESSAGES_READ: &'static str = "messages:read";
pub const MESSAGES_LIST: &'static str = "messages:list";
pub const MESSAGES_EXPORT: &'static str = "messages:export";
pub const SETTINGS_READ: &'static str = "settings:read";
pub const SETTINGS_WRITE: &'static str = "settings:write";
pub const TOKENS_MANAGE: &'static str = "tokens:manage";
pub const WEBHOOKS_LIST: &'static str = "webhooks:list";
pub const WEBHOOKS_WRITE: &'static str = "webhooks:write";
pub const WEBHOOKS_DELETE: &'static str = "webhooks:delete";
pub fn new(s: impl Into<String>) -> Self {
Self(s.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TokenRequest {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub ttl: Option<u64>,
#[serde(default)]
pub scopes: Vec<JwtScope>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TokenResponse {
pub id: String,
pub token_type: String,
pub access_token: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub refresh_token: Option<String>,
pub expires_at: DateTime<Utc>,
}