briteverify_rs/types/
enums.rs

1//! ## BriteVerify API Well-Known Status & Result Enumerations
2///
3// Standard Library Imports
4use std::fmt;
5
6// Conditional Imports
7#[doc(hidden)]
8#[cfg(any(test, tarpaulin))]
9#[cfg_attr(any(test, tarpaulin), allow(unused_imports))]
10pub use self::foundry::*;
11
12// <editor-fold desc="// BatchState ...">
13
14/// The current state of a given bulk verification list
15#[allow(missing_docs)]
16#[derive(Copy, Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
17#[serde(rename_all(serialize = "snake_case", deserialize = "snake_case"))]
18pub enum BatchState {
19    Open,
20    Closed,
21    Deleted,
22    Expired,
23    Pending,
24    Prepped,
25    Success,
26    Complete,
27    NotFound,
28    Delivered,
29    Verifying,
30    Terminated,
31    ImportError,
32    MissingData,
33    ExceedsLimit,
34    InvalidState,
35    DuplicateData,
36    ListUploadsIncomplete,
37    #[serde(other)]
38    Unknown,
39}
40
41impl BatchState {
42    /// Check if an instance is `Unknown`
43    pub fn is_unknown(&self) -> bool {
44        matches!(self, Self::Unknown)
45    }
46}
47
48impl Default for BatchState {
49    #[cfg_attr(tarpaulin, coverage(off))]
50    fn default() -> Self {
51        Self::Unknown
52    }
53}
54
55impl fmt::Display for BatchState {
56    #[cfg_attr(tarpaulin, coverage(off))]
57    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58        let display = match self {
59            Self::Open => "open",
60            Self::Closed => "closed",
61            Self::Deleted => "deleted",
62            Self::Expired => "expired",
63            Self::Pending => "pending",
64            Self::Prepped => "prepped",
65            Self::Success => "success",
66            Self::Unknown => "unknown",
67            Self::Complete => "complete",
68            Self::NotFound => "notfound",
69            Self::Delivered => "delivered",
70            Self::Verifying => "verifying",
71            Self::Terminated => "terminated",
72            Self::ImportError => "importerror",
73            Self::MissingData => "missingdata",
74            Self::ExceedsLimit => "exceeds_limit",
75            Self::InvalidState => "invalidstate",
76            Self::DuplicateData => "duplicate_data",
77            Self::ListUploadsIncomplete => "list_uploads_incomplete",
78        };
79
80        write!(f, "{}", display)
81    }
82}
83
84impl<'value, T: Into<&'value str>> From<T> for BatchState {
85    #[cfg_attr(tarpaulin, coverage(off))]
86    fn from(value: T) -> Self {
87        let is_quote = |val: char| -> bool { val == '"' || val == '\'' };
88
89        let value = value
90            .into()
91            .trim_start_matches(is_quote)
92            .trim_end_matches(is_quote)
93            .trim()
94            .to_lowercase();
95
96        match value.as_str() {
97            "open" => Self::Open,
98            "closed" => Self::Closed,
99            "deleted" => Self::Deleted,
100            "expired" => Self::Expired,
101            "pending" => Self::Pending,
102            "prepped" => Self::Prepped,
103            "success" => Self::Success,
104            "complete" => Self::Complete,
105            "notfound" => Self::NotFound,
106            "delivered" => Self::Delivered,
107            "verifying" => Self::Verifying,
108            "terminated" => Self::Terminated,
109            "importerror" | "import_error" | "import-error" => Self::ImportError,
110            "exceedslimit" | "exceeds_limit" | "exceeds-limit" => Self::ExceedsLimit,
111            "invalidstate" | "invalid_state" | "invalid-state" => Self::InvalidState,
112            "duplicatedata" | "duplicate_data" | "duplicate-data" => Self::DuplicateData,
113            "missing" | "missingdata" | "missing_data" | "missing-data" => Self::MissingData,
114            "incomplete"
115            | "uploadincomplete"
116            | "uploadsincomplete"
117            | "upload_incomplete"
118            | "upload-incomplete"
119            | "uploads_incomplete"
120            | "uploads-incomplete"
121            | "listuploadincomplete"
122            | "listuploadsincomplete"
123            | "list_uploads_incomplete"
124            | "list-uploads-incomplete" => Self::ListUploadsIncomplete,
125            _ => Self::Unknown,
126        }
127    }
128}
129
130// </editor-fold desc="// BatchState ...">
131
132// <editor-fold desc="// VerificationError ...">
133
134/// The end result of a given verification
135#[allow(missing_docs)]
136#[derive(Copy, Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
137#[serde(rename_all(serialize = "snake_case", deserialize = "snake_case"))]
138pub enum VerificationError {
139    Disposable,
140    PMBRequired,
141    RoleAddress,
142    SuiteInvalid,
143    SuiteMissing,
144    InvalidFormat,
145    InvalidPrefix,
146    MultipleMatch,
147    UnknownStreet,
148    ZipCodeInvalid,
149    BlankPhoneNumber,
150    BoxNumberInvalid,
151    BoxNumberMissing,
152    EmailDomainInvalid,
153    InvalidPhoneNumber,
154    MailboxFullInvalid,
155    DirectionalsInvalid,
156    EmailAccountInvalid,
157    EmailAddressInvalid,
158    StreetNumberInvalid,
159    StreetNumberMissing,
160    SuiteInvalidMissing,
161    MissingMinimumInputs,
162    NonDeliverableAddress,
163    #[serde(other)]
164    Unknown,
165}
166
167impl Default for VerificationError {
168    #[cfg_attr(tarpaulin, coverage(off))]
169    fn default() -> Self {
170        Self::Unknown
171    }
172}
173
174impl fmt::Display for VerificationError {
175    #[cfg_attr(tarpaulin, coverage(off))]
176    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
177        let display: String = (match self {
178            Self::Unknown => "unknown",
179            Self::Disposable => "disposable",
180            Self::PMBRequired => "pmb_required",
181            Self::RoleAddress => "role_address",
182            Self::SuiteInvalid => "suite_invalid",
183            Self::SuiteMissing => "suite_missing",
184            Self::InvalidFormat => "invalid_format",
185            Self::InvalidPrefix => "invalid_prefix",
186            Self::MultipleMatch => "multiple_match",
187            Self::UnknownStreet => "unknown_street",
188            Self::ZipCodeInvalid => "zip_code_invalid",
189            Self::BlankPhoneNumber => "blank_phone_number",
190            Self::BoxNumberInvalid => "box_number_invalid",
191            Self::BoxNumberMissing => "box_number_missing",
192            Self::EmailDomainInvalid => "email_domain_invalid",
193            Self::InvalidPhoneNumber => "invalid_phone_number",
194            Self::MailboxFullInvalid => "mailbox_full_invalid",
195            Self::DirectionalsInvalid => "directionals_invalid",
196            Self::EmailAccountInvalid => "email_account_invalid",
197            Self::EmailAddressInvalid => "email_address_invalid",
198            Self::StreetNumberInvalid => "street_number_invalid",
199            Self::StreetNumberMissing => "street_number_missing",
200            Self::SuiteInvalidMissing => "suite_invalid_missing",
201            Self::MissingMinimumInputs => "missing_minimum_inputs",
202            Self::NonDeliverableAddress => "non_deliverable_address",
203        })
204        .to_string();
205
206        write!(f, "{}", display)
207    }
208}
209
210// </editor-fold desc="// VerificationError ...">
211
212// <editor-fold desc="// VerificationStatus ...">
213
214/// The end result of a given verification
215#[allow(missing_docs)]
216#[derive(Copy, Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
217#[serde(rename_all(serialize = "snake_case", deserialize = "snake_case"))]
218pub enum VerificationStatus {
219    Valid,
220    Invalid,
221    AcceptAll,
222    #[serde(other)]
223    Unknown,
224}
225
226impl Default for VerificationStatus {
227    #[cfg_attr(tarpaulin, coverage(off))]
228    fn default() -> Self {
229        Self::Unknown
230    }
231}
232
233impl fmt::Display for VerificationStatus {
234    #[cfg_attr(tarpaulin, coverage(off))]
235    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
236        let display = match self {
237            Self::Valid => "valid",
238            Self::Invalid => "invalid",
239            Self::Unknown => "unknown",
240            Self::AcceptAll => "accept-all",
241        };
242
243        write!(f, "{}", display)
244    }
245}
246
247// </editor-fold desc="// VerificationStatus ...">
248
249// <editor-fold desc="// BulkListDirective ...">
250
251/// The current state of a given batch verification job
252#[allow(missing_docs)]
253#[derive(Copy, Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
254#[serde(rename_all(serialize = "snake_case", deserialize = "snake_case"))]
255pub enum BulkListDirective {
256    Start,
257    Terminate,
258    #[serde(other)]
259    Unknown,
260}
261
262impl Default for BulkListDirective {
263    #[cfg_attr(tarpaulin, coverage(off))]
264    fn default() -> Self {
265        Self::Unknown
266    }
267}
268
269impl fmt::Display for BulkListDirective {
270    #[cfg_attr(tarpaulin, coverage(off))]
271    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
272        let display = match self {
273            Self::Start => "start",
274            Self::Unknown => "unknown",
275            Self::Terminate => "terminate",
276        };
277
278        write!(f, "{}", display)
279    }
280}
281
282impl From<bool> for BulkListDirective {
283    #[cfg_attr(tarpaulin, coverage(off))]
284    fn from(value: bool) -> Self {
285        match value {
286            true => Self::Start,
287            false => Self::Unknown,
288        }
289    }
290}
291
292impl From<String> for BulkListDirective {
293    #[cfg_attr(tarpaulin, coverage(off))]
294    fn from(value: String) -> Self {
295        Self::from(value.as_str())
296    }
297}
298
299impl<'value> From<&'value str> for BulkListDirective {
300    #[cfg_attr(tarpaulin, coverage(off))]
301    fn from(value: &'value str) -> Self {
302        let value = value.trim().to_lowercase();
303
304        match value.as_str() {
305            "start" | "true" => Self::Start,
306            "terminate" | "stop" => Self::Terminate,
307            _ => Self::Unknown,
308        }
309    }
310}
311
312impl<T: ToString> From<Option<T>> for BulkListDirective {
313    #[cfg_attr(tarpaulin, coverage(off))]
314    fn from(value: Option<T>) -> Self {
315        Self::from(value.map_or(String::new(), |directive| directive.to_string()))
316    }
317}
318
319// </editor-fold desc="// BulkListDirective ...">
320
321// <editor-fold desc="// Test Helpers & Factory Implementations ...">
322
323#[doc(hidden)]
324#[cfg(any(test, tarpaulin))]
325mod foundry {}
326
327// </editor-fold desc="// Test Helpers & Factory Implementations ...">