Skip to main content

idkollen_client/models/
age_verification.rs

1use serde::{Deserialize, Serialize};
2
3use super::common::ApiErrorCode;
4use super::url::Url;
5
6/// Request body for starting an age verification session.
7///
8/// At least one of `min_age` or `max_age` must be provided.
9/// If both are given, `max_age` must be >= `min_age`.
10#[must_use]
11#[derive(Debug, Clone, Default, Serialize)]
12#[serde(rename_all = "camelCase")]
13pub struct AgeVerificationRequest {
14    /// Minimum age (inclusive).
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub min_age: Option<u32>,
17    /// Maximum age (inclusive).
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub max_age: Option<u32>,
20    /// Reference ID returned verbatim in the result and callback.
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub ref_id: Option<String>,
23    /// URL to receive the result callback on success or failure.
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub callback_url: Option<Url>,
26    /// URL to redirect the user to after completing age verification.
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub redirect_url: Option<Url>,
29}
30
31impl AgeVerificationRequest {
32    #[inline]
33    pub fn new() -> Self {
34        Self::default()
35    }
36
37    #[inline]
38    pub fn min_age(mut self, age: u32) -> Self {
39        self.min_age = Some(age);
40        self
41    }
42
43    #[inline]
44    pub fn max_age(mut self, age: u32) -> Self {
45        self.max_age = Some(age);
46        self
47    }
48
49    #[inline]
50    pub fn ref_id(mut self, ref_id: impl Into<String>) -> Self {
51        self.ref_id = Some(ref_id.into());
52        self
53    }
54
55    #[inline]
56    pub fn callback_url(mut self, url: Url) -> Self {
57        self.callback_url = Some(url);
58        self
59    }
60
61    #[inline]
62    pub fn redirect_url(mut self, url: Url) -> Self {
63        self.redirect_url = Some(url);
64        self
65    }
66}
67
68/// Age verification session status.
69#[non_exhaustive]
70#[derive(Debug, Clone, Deserialize)]
71#[serde(tag = "status")]
72pub enum AgeVerificationStatus {
73    #[serde(rename = "PENDING")]
74    Pending(AgeVerificationPending),
75    #[serde(rename = "COMPLETED")]
76    Completed(AgeVerificationCompleted),
77    #[serde(rename = "FAILED")]
78    Failed(AgeVerificationFailed),
79}
80
81/// Returned while the user has not yet completed age verification.
82#[derive(Debug, Clone, Deserialize)]
83#[serde(rename_all = "camelCase")]
84pub struct AgeVerificationPending {
85    pub id: String,
86    pub url: Option<String>,
87    pub min_age: Option<u32>,
88    pub max_age: Option<u32>,
89}
90
91/// Returned when the age verification session has completed.
92#[derive(Debug, Clone, Deserialize)]
93#[serde(rename_all = "camelCase")]
94pub struct AgeVerificationCompleted {
95    pub id: String,
96    /// `true` if the user's age is within the requested range.
97    pub age_verified: bool,
98}
99
100/// Returned when the age verification session has failed.
101#[derive(Debug, Clone, Deserialize)]
102#[serde(rename_all = "camelCase")]
103pub struct AgeVerificationFailed {
104    pub id: String,
105    pub error: ApiErrorCode,
106}