1#[derive(Debug, Clone, Default)]
5pub struct AuthResult {
6 pub user_id: Option<String>,
8
9 pub metadata: Option<AuthMetadata>,
11}
12
13impl AuthResult {
14 #[inline]
16 pub fn anonymous() -> Self {
17 Self::default()
18 }
19
20 #[inline]
22 pub fn with_user_id(user_id: impl Into<String>) -> Self {
23 Self {
24 user_id: Some(user_id.into()),
25 metadata: None,
26 }
27 }
28
29 #[inline]
31 pub fn with_metadata(mut self, metadata: AuthMetadata) -> Self {
32 self.metadata = Some(metadata);
33 self
34 }
35}
36
37#[derive(Debug, Clone, Default)]
39pub struct AuthMetadata {
40 pub traffic_limit: u64,
42
43 pub traffic_used: u64,
45
46 pub expires_at: u64,
48
49 pub enabled: bool,
51}
52
53impl AuthMetadata {
54 pub fn new() -> Self {
56 Self {
57 traffic_limit: 0,
58 traffic_used: 0,
59 expires_at: 0,
60 enabled: true,
61 }
62 }
63
64 #[inline]
66 pub fn is_over_limit(&self) -> bool {
67 self.traffic_limit > 0 && self.traffic_used >= self.traffic_limit
68 }
69
70 #[inline]
72 pub fn is_expired(&self, now: u64) -> bool {
73 self.expires_at > 0 && now >= self.expires_at
74 }
75}