1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5use super::{null_default, Deduction};
6
7#[derive(Debug, Clone, Default, PartialEq, Serialize)]
9pub struct BulkRequest {
10 #[serde(skip_serializing_if = "Option::is_none")]
11 pub ips: Option<Vec<String>>,
12 #[serde(skip_serializing_if = "Option::is_none")]
13 pub input: Option<String>,
14}
15
16impl BulkRequest {
17 pub fn ips<I, S>(ips: I) -> Self
19 where
20 I: IntoIterator<Item = S>,
21 S: Into<String>,
22 {
23 BulkRequest {
24 ips: Some(ips.into_iter().map(Into::into).collect()),
25 input: None,
26 }
27 }
28
29 pub fn input(input: impl Into<String>) -> Self {
31 BulkRequest {
32 ips: None,
33 input: Some(input.into()),
34 }
35 }
36}
37
38#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
40#[serde(default, rename_all = "camelCase")]
41pub struct BulkCheck {
42 pub submitted: i64,
43 pub unique: i64,
44 pub duplicates: i64,
45 #[serde(deserialize_with = "null_default")]
46 pub invalid: Vec<String>,
47 #[serde(deserialize_with = "null_default")]
49 pub summary: HashMap<String, i64>,
50 #[serde(deserialize_with = "null_default")]
51 pub results: Vec<BulkResult>,
52 pub plan_required: Option<String>,
53}
54
55#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
57#[serde(default, rename_all = "camelCase")]
58pub struct BulkResult {
59 pub input: String,
60 pub ip: String,
61 pub port: Option<u16>,
62 pub score: Option<i64>,
63 pub grade: Option<String>,
64 pub verdict: Option<String>,
65 pub classification: String,
66 pub confidence: f64,
67 pub anonymized: bool,
68 pub vpn_provider: Option<String>,
69 pub is_tor_exit: bool,
70 pub in_vpn_range: bool,
71 pub in_datacenter_range: bool,
72 pub asn: Option<String>,
73 pub asn_name: Option<String>,
74 pub asn_type: Option<String>,
75 pub country: Option<String>,
76 #[serde(deserialize_with = "null_default")]
77 pub deductions: Vec<Deduction>,
78 pub locked: Vec<String>,
79}
80
81#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
83#[serde(default, rename_all = "camelCase")]
84pub struct BulkEvent {
85 #[serde(rename = "type")]
87 pub kind: String,
88 pub index: i64,
89 pub total: i64,
90 pub input: String,
91 pub reason: String,
92 pub message: String,
93 pub error: String,
94 pub ip: String,
95 #[serde(deserialize_with = "null_default")]
96 pub verdict: String,
97 pub classification: String,
98 pub confidence: f64,
99 pub anonymized: bool,
100 #[serde(deserialize_with = "null_default")]
101 pub vpn_provider: String,
102 #[serde(deserialize_with = "null_default")]
103 pub score: i64,
104 #[serde(deserialize_with = "null_default")]
105 pub grade: String,
106 pub is_tor_exit: bool,
107 pub asn: String,
108 pub asn_name: String,
109 pub asn_type: String,
110 pub country: String,
111 pub processed: i64,
112 pub failed: i64,
113 pub metered: i64,
114 pub plan_required: String,
116 pub locked: Vec<String>,
118}
119
120impl BulkEvent {
121 pub fn complete(&self) -> bool {
123 self.kind == "done"
124 && self.reason == "complete"
125 && i128::from(self.processed) + i128::from(self.failed) >= i128::from(self.total)
126 }
127}