polestar_api/models/
vehicle.rs

1//! Vehicle data models.
2
3use serde::{Deserialize, Serialize};
4
5/// Complete vehicle information.
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct Vehicle {
8    /// Vehicle Identification Number (VIN).
9    pub vin: String,
10
11    /// Internal vehicle identifier.
12    #[serde(rename = "internalVehicleIdentifier")]
13    pub internal_vehicle_identifier: Option<String>,
14
15    /// Registration number.
16    #[serde(rename = "registrationNo")]
17    pub registration_number: Option<String>,
18
19    /// Market (e.g., "US", "EU").
20    pub market: Option<String>,
21
22    /// Vehicle content and specifications.
23    pub content: VehicleContent,
24}
25
26/// Vehicle content and specifications.
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct VehicleContent {
29    /// Model information.
30    pub model: ModelInfo,
31
32    /// Vehicle images.
33    pub images: Option<Images>,
34
35    /// Vehicle specifications.
36    pub specification: Option<VehicleSpecifications>,
37}
38
39/// Model information.
40#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct ModelInfo {
42    /// Model code.
43    pub code: Option<String>,
44
45    /// Model name.
46    pub name: Option<String>,
47}
48
49/// Vehicle images.
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct Images {
52    /// Studio images.
53    pub studio: Option<StudioImages>,
54}
55
56/// Studio images.
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct StudioImages {
59    /// Image URL.
60    pub url: Option<String>,
61
62    /// Available angles.
63    pub angles: Option<Vec<String>>,
64}
65
66/// Vehicle specifications.
67#[derive(Debug, Clone, Serialize, Deserialize)]
68pub struct VehicleSpecifications {
69    /// Motor specifications.
70    pub motor: Option<MotorSpec>,
71
72    /// Battery specifications.
73    pub battery: Option<String>,
74
75    /// Torque specification.
76    pub torque: Option<String>,
77}
78
79/// Motor specifications.
80#[derive(Debug, Clone, Serialize, Deserialize)]
81pub struct MotorSpec {
82    /// Power output.
83    pub power: Option<String>,
84
85    /// Torque.
86    pub torque: Option<String>,
87
88    /// 0-100 km/h acceleration time.
89    pub acceleration: Option<String>,
90}
91
92/// Battery specifications.
93#[derive(Debug, Clone, Serialize, Deserialize)]
94pub struct BatterySpec {
95    /// Battery capacity.
96    pub capacity: Option<String>,
97
98    /// Range.
99    pub range: Option<String>,
100}
101
102#[cfg(test)]
103mod tests {
104    use super::*;
105
106    #[test]
107    fn test_vehicle_deserialization() {
108        let json = r#"{
109            "vin": "TEST123",
110            "market": "US",
111            "content": {
112                "model": {
113                    "code": "P2",
114                    "name": "Polestar 2"
115                }
116            }
117        }"#;
118
119        let vehicle: Vehicle = serde_json::from_str(json).unwrap();
120        assert_eq!(vehicle.vin, "TEST123");
121        assert_eq!(vehicle.market, Some("US".to_string()));
122        assert_eq!(vehicle.content.model.name, Some("Polestar 2".to_string()));
123    }
124}