dinio_sdk/models/geo_ban.rs
1use serde::{Deserialize, Serialize};
2use uuid::Uuid;
3
4use crate::models::GeoCatalog;
5use crate::ops::{GeoArea, GeoLevel};
6
7/// A geo ban on one record value: Relay does not answer with that value to clients in
8/// the area. Applies to A and AAAA values only; Relay ignores bans on other types.
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct GeoBan {
11 /// Ban id.
12 pub uuid: Uuid,
13 /// The banned record value.
14 pub record_id: Uuid,
15 /// `Region`, `Subregion` or `Country` (kept as a string for forward compatibility).
16 pub level: String,
17 /// Numeric code at that level (e.g. ISO 3166-1 numeric for `Country`).
18 pub code: u32,
19 /// Unix seconds.
20 pub created_at: i64,
21 /// Unix seconds.
22 pub updated_at: i64,
23}
24
25impl GeoBan {
26 /// The banned area, if the level label is known.
27 pub fn area(&self) -> Option<GeoArea> {
28 let level: GeoLevel = self.level.parse().ok()?;
29 Some(GeoArea {
30 level,
31 code: u16::try_from(self.code).ok()?,
32 })
33 }
34
35 /// `Country Croatia (191)`, or `<level> <code>` if the catalog does not know the
36 /// area.
37 pub fn describe(&self, catalog: &GeoCatalog) -> String {
38 self.area().map_or_else(
39 || format!("{} {}", self.level, self.code),
40 |a| catalog.describe(a),
41 )
42 }
43}