1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use serde::{Deserialize, Serialize};

/// Tracking response from DHL
#[derive(Debug, Serialize, Deserialize)]
pub struct Tracking {
    pub shipments: Vec<Shipment>,
}

/// Single Shipment details
#[derive(Debug, Serialize, Deserialize)]
pub struct Shipment {
    pub id: String,
    pub service: String,
    pub origin: PointLocation,
    pub destination: PointLocation,
    pub status: ShipmentStatus,
    pub details: ShipmentDetails,
    pub events: Vec<ShipmentEvent>,
}

/// Point location
#[derive(Debug, Serialize, Deserialize)]
pub struct PointLocation {
    pub address: Address,
    #[serde(rename = "servicePoint")]
    pub service_point: Option<ServicePoint>,
}

/// Address
#[derive(Debug, Serialize, Deserialize)]
pub struct Address {
    #[serde(rename = "addressLocality")]
    pub address_locality: String,
}

/// Service point
#[derive(Debug, Serialize, Deserialize)]
pub struct ServicePoint {
    pub url: String,
    pub label: String,
}

/// Status of a shipment
#[derive(Debug, Serialize, Deserialize)]
pub struct ShipmentStatus {
    pub timestamp: String,
    pub location: PointLocation,
    pub description: String,
}

/// Shipment details, contains proof of delivery, number of pieces and piece ids
#[derive(Debug, Serialize, Deserialize)]
pub struct ShipmentDetails {
    #[serde(rename = "proofOfDelivery")]
    pub proof_of_delivery: Option<ProofOfDelivery>,

    #[serde(rename = "proofOfDeliverySignedAvailable")]
    pub proof_of_delivery_signed_available: bool,

    #[serde(rename = "totalNumberOfPieces")]
    pub total_number_of_pieces: i32,

    #[serde(rename = "pieceIds")]
    pub piece_ids: Vec<String>,
}

/// Proof of delivery
#[derive(Debug, Serialize, Deserialize)]
pub struct ProofOfDelivery {
    #[serde(rename = "signatureUrl")]
    pub signature_url: String,

    #[serde(rename = "documentUrl")]
    pub document_url: String,
}

/// Single shipment event
#[derive(Debug, Serialize, Deserialize)]
pub struct ShipmentEvent {
    pub timestamp: String,
    pub location: PointLocation,
    pub description: String,
}