gistools/readers/gbfs/schema_v3/geofencing_zones.rs
1use crate::readers::{GBFSName, gbfs_bool_or_int};
2use alloc::{string::String, vec::Vec};
3use s2json::{FeatureCollection, MValue, ValuePrimitive};
4use serde::{Deserialize, Serialize};
5
6/// # GBFS Geofencing Zones Schema V3.1-RC & V3.0
7/// Describes geofencing zones and their associated rules and attributes (added in v2.1-RC).
8///
9/// ## Links
10/// - [GBFS Specification V3.1-RC](https://github.com/MobilityData/gbfs/blob/v3.1-RC/gbfs.md#geofencing_zonesjson)
11/// - [GBFS Specification V3.0](https://github.com/MobilityData/gbfs/blob/v3.0/gbfs.md#geofencing_zonesjson)
12pub type GBFSGeofencingZonesV3 = GBFSGeofencingZonesV30;
13
14/// GBFS V3: Restrictions that apply within the area of the polygon.
15#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, ValuePrimitive)]
16pub struct GBFSGeofencingZonesV3PropertiesRule {
17 // /// Array of vehicle type IDs for which these restrictions apply.
18 // pub vehicle_type_ids: Option<Vec<String>>,
19 /// Is the ride allowed to start in this zone?
20 #[serde(deserialize_with = "gbfs_bool_or_int")]
21 pub ride_start_allowed: bool,
22 /// Is the ride allowed to end in this zone?
23 #[serde(deserialize_with = "gbfs_bool_or_int")]
24 pub ride_end_allowed: bool,
25 /// Is the ride allowed to travel through this zone?
26 #[serde(deserialize_with = "gbfs_bool_or_int")]
27 pub ride_through_allowed: bool,
28 /// Maximum speed allowed, in kilometers per hour.
29 /// **minimum** 0
30 pub maximum_speed_kph: Option<f64>,
31 /// Vehicle MUST be parked at stations defined in station_information.json within this zone.
32 pub station_parking: Option<bool>,
33}
34
35/// Properties of a geofencing zone
36#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, MValue)]
37pub struct GBFSGeofencingZonesV3Properties {
38 /// Public name of the geofencing zone.
39 pub name: Vec<GBFSName>,
40 /// Start time of the geofencing zone in RFC3339 format.
41 /// **format** date-time
42 pub start: Option<String>,
43 /// End time of the geofencing zone in RFC3339 format.
44 /// **format** date-time
45 pub end: Option<String>,
46 /// Array of rules defining restrictions within the geofence.
47 pub rules: Option<Vec<GBFSGeofencingZonesV3PropertiesRule>>,
48}
49
50/// Container for GeoJSON FeatureCollection of geofencing zones
51#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
52pub struct GBFSGeofencingZonesV30Data {
53 /// GeoJSON FeatureCollection of geofencing zones
54 pub geofencing_zones: FeatureCollection<(), GBFSGeofencingZonesV3Properties, MValue>,
55 /// Array of global rules defining restrictions that apply by default.
56 pub global_rules: Vec<GBFSGeofencingZonesV3PropertiesRule>,
57}
58
59/// # GBFS Geofencing Zones Schema V3.0
60/// Describes geofencing zones and their associated rules and attributes (added in v2.1-RC).
61///
62/// ## Links
63/// - [GBFS Specification](https://github.com/MobilityData/gbfs/blob/v3.0/gbfs.md#geofencing_zonesjson)
64#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
65pub struct GBFSGeofencingZonesV30 {
66 /// Last time the data in the feed was updated in RFC3339 format.
67 /// **Format**: date-time
68 pub last_updated: String,
69 /// Number of seconds before the data in the feed will be updated again (0 if the data should always be refreshed).
70 /// **Minimum**: 0
71 pub ttl: u64,
72 /// GBFS version number to which the feed conforms, according to the versioning framework.
73 /// **Const**: '3.0'
74 pub version: String,
75 /// Array that contains geofencing information for the system.
76 pub data: GBFSGeofencingZonesV30Data,
77}