gistools/readers/gbfs/schema_v3/vehicle_status.rs
1use crate::readers::{GBFSRentalUri, gbfs_bool_or_int};
2use alloc::{string::String, vec::Vec};
3use s2json::MValue;
4use serde::{Deserialize, Serialize};
5
6/// # GBFS Vehicle Status Schema V3.1-RC & V3.0
7/// Describes the vehicles that are available for rent (as of v3.0, formerly free_bike_status).
8///
9/// ## Links
10/// - [GBFS Specification V3.1-RC](https://github.com/MobilityData/gbfs/blob/v3.1-RC/gbfs.md#vehicle_statusjson)
11/// - [GBFS Specification V3.0](https://github.com/MobilityData/gbfs/blob/v3.0/gbfs.md#vehicle_statusjson)
12pub type GBFSVehicleStatusV3 = GBFSVehicleStatusV30;
13
14/// Vehicle Equipment Type
15#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
16pub enum GBFSFreeBikeStatusVehicleEquipmentV3 {
17 /// Child Seat A
18 #[serde(rename = "child_seat_a")]
19 #[default]
20 ChildSeatA,
21 /// Child Seat B
22 #[serde(rename = "child_seat_b")]
23 ChildSeatB,
24 /// Child Seat C
25 #[serde(rename = "child_seat_c")]
26 ChildSeatC,
27 /// Winter Tires
28 #[serde(rename = "winter_tires")]
29 WinterTires,
30 /// Snow Chains
31 #[serde(rename = "snow_chains")]
32 SnowChains,
33}
34
35/// GBFS Vehicle V3
36#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, MValue)]
37pub struct GBFSVehicleV3 {
38 /// Rotating (as of v2.0) identifier of a vehicle.
39 pub vehicle_id: String,
40 /// The latitude of the vehicle.
41 /// **Range**: [-90, 90]
42 pub lat: Option<f64>,
43 /// The longitude of the vehicle.
44 /// **Range**: [-180, 180]
45 pub lon: Option<f64>,
46 /// Is the vehicle currently reserved?
47 #[serde(deserialize_with = "gbfs_bool_or_int")]
48 pub is_reserved: bool,
49 /// Is the vehicle currently disabled (broken)?
50 #[serde(deserialize_with = "gbfs_bool_or_int")]
51 pub is_disabled: bool,
52 /// Contains rental URIs for Android, iOS, and web.
53 pub rental_uris: Option<GBFSRentalUri>,
54 /// The vehicle_type_id of this vehicle (added in v2.1-RC).
55 pub vehicle_type_id: Option<String>,
56 /// The last time this vehicle reported its status to the operator's backend.
57 /// **Format**: date-time
58 pub last_reported: Option<String>,
59 /// The furthest distance in meters the vehicle can travel without recharging or refueling.
60 /// **Minimum**: 0
61 pub current_range_meters: Option<f64>,
62 /// Current percentage of fuel or battery power remaining in the vehicle.
63 /// **Range**: [0, 1]
64 pub current_fuel_percent: Option<f64>,
65 /// Identifier referencing the station_id if the vehicle is currently at a station.
66 pub station_id: Option<String>,
67 /// The station_id of the station this vehicle must be returned to.
68 pub home_station_id: Option<String>,
69 /// The plan_id of the pricing plan this vehicle is eligible for.
70 pub pricing_plan_id: Option<String>,
71 // /// List of vehicle equipment provided by the operator.
72 // /// **Enum**: ['child_seat_a', 'child_seat_b', 'child_seat_c', 'winter_tires', 'snow_chains']
73 // pub vehicle_equipment: Option<Vec<GBFSFreeBikeStatusVehicleEquipmentV3>>,
74 /// The date and time when any rental of the vehicle must be completed.
75 /// **Pattern**: `^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(([+-]([0-9]{2}):([0-9]{2}))|Z)$`
76 pub available_until: Option<String>,
77}
78
79/// GBFS Vehicle Status Data V3.0
80#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
81pub struct GBFSVehicleStatusDataV30 {
82 /// List of vehicles
83 pub vehicles: Vec<GBFSVehicleV3>,
84}
85
86/// # GBFS Vehicle Status Schema V3.0
87/// Describes the vehicles that are available for rent (as of v3.0, formerly free_bike_status).
88///
89/// ## Links
90/// - [GBFS Specification](https://github.com/MobilityData/gbfs/blob/v3.1-RC/gbfs.md#vehicle_statusjson)
91#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
92pub struct GBFSVehicleStatusV30 {
93 /// Last time the data in the feed was updated in RFC3339 format.
94 pub last_updated: String,
95 /// Number of seconds before the data in the feed will be updated again (0 if the data should always be refreshed).
96 pub ttl: u64,
97 /// GBFS version number to which the feed conforms.
98 pub version: String,
99 /// Vehicle data containing information on available vehicles for rent.
100 pub data: GBFSVehicleStatusDataV30,
101}