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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
use serde::{Deserialize, Serialize};

use crate::models::general::{
    LocalDateTime,
    ManifestItem,
    VerificationRequirement,
    TestSpecifications,
    CourierInfo,
    WaypointInfo,
    ManifestInfo,
    RelatedDelivery,
    StructuredAddress
};
/// # Request Body Parameters
///
/// | Name | Type | Description |
/// | :--- | :--- | :--- |
/// | dropoff_address | string - Structured Address | (required) For single string, format is : "Street Address, City, State, Zip" |
/// | dropoff_name | string | (required) Name of the place where the courier will make the dropoff. |
/// | dropoff_phone_number | string | (required) The phone number of the dropoff location. |
/// | manifest | string | (required) [SOON TO BE DEPRECATED] 'manifest_items` should be used instead. |
/// | manifest_items | Manifestltem[] | (required) List of items being delivered. |
/// | pickup_address | string | (required) Pickup address in Street Address, City, State, Zip format. |
/// | pickup_name | string | (required) Name of the place where the courier will make the pickup. |
/// | pickup_phone_number | string | (required) Name of the place where the courier will make the pickup. |
/// | deliverable_action | DeliverableAction | Specify the "happy path" action for the courier to take on a delivery. When used, delivery action can be set to "leave at door" for a contactless delivery. Cannot leave at door when signature or ID verification requirements are applied when creating a delivery. Photo confirmation of delivery will be automatically applied as a requirement to complete dropoff. |
/// | dropoff_business_name | string | Business name of the dropoff location. |
/// | dropoff_latitude | double | Dropoff latitude coordinate. |
/// | dropoff_longitude | double | Dropoff longitude coordinate. |
/// | dropoff_notes | string | Additional instructions for the courier at the dropoff location. Max 280 characters. |
/// | dropoff_seller_notes | string | Additional instructions provided by the merchant for the dropoff. Max 280 characters. |
/// | dropoff_verification | VerificationRequirement | Verification steps (i.e. barcode scanning) that must be taken before the dropoff can be completed. |
/// | manifest_reference | string | Reference that identifies the manifest. Use this to connect a delivery to corresponding information in your system. |
/// | manifest_total_value | integer | Value (in US cents) of the items in the delivery. i.e.: $10.99=>1099. |
/// | pickup_business_name | string | Business name of the pickup location. |
/// | pickup_latitude | double | Pickup latitude coordinate. |
/// | pickup_longitude | double | Pickup longitude coordinate. |
/// | pickup_notes | string | Additional instructions for the courier at the pickup location. Max 280 characters. |
/// | pickup_verification | VerificationRequirement | Verification steps (i.e. barcode scanning) that must be taken before the pickup can be completed. |
/// | quote_id | string | The ID of a previously generated delivery quote. |
/// | undeliverable_action | UndeliverableAction | Specify the "unhappy path" action for the courier to take on a delivery once a normal delivery attempt is made and a customer is not available. |
/// | pickup_ready_dt | timestamp (RFC 3339) | Beginning of the window when an order must be picked up. Must be less than 30 days in the future. |
/// | pickup_deadline_dt | timestamp (RFC 3339) | End of the window when an order may be picked up. Must be at least 10 mins later than pickup_ready_dt and at least 20 minutes in the future from now. |
/// | dropoff_ready_dt | timestamp (RFC 3339) | Beginning of the window when an order must be dropped off. Must be less than or equal to pickup_deadline_dt . |
/// | dropoff_deadline_dt | timestamp (RFC 3339) | End of the window when an order must be dropped off. Must be at least 20 mins later than dropoff_ready_dt and must be greater than or equal to pickup_deadline_dt. |
/// | requires_dropoff_signature | boolean | [DEPRECATED] Flag to indicate this delivery requires signature capture at dropoff. |
/// | requires_id | boolean | Flag to indicate this delivery requires ID check (minimum age) at dropoff |
/// | tip | integer | Upfront tip amount. 0.01 of the national currency (cents in US or $0.01 ) |
/// | idempotency_key | string | A key which is used to avoid duplicate order creation with identical idempotency keys for the same account. The key persists for a set time frame, defaulting to 6 hours |
/// | external_store_id | string | (Optional) Unique identifier used by our Partners to reference a Store or Location |
/// | return_verification | VerificationRequirement | Verification steps (barcode scanning, picture, or signature) that must be taken before the return can be completed. |
///
#[derive(Serialize, Debug, Default)]
#[serde(rename_all = "snake_case")]
pub struct CreateDeliveryRequest {
    pub dropoff_address: String, // StructuredAddress.to_string(),
    pub dropoff_name: String,
    pub dropoff_phone_number: String,
    //#[serde(skip_serializing_if = "String::is_empty")]
    //pub manifest: String,
    pub manifest_items: Vec<ManifestItem>,
    pub pickup_address: String, // StructuredAddress.to_string(),
    pub pickup_name: String,
    pub pickup_phone_number: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub deliverable_action: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub dropoff_business_name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub dropoff_latitude: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub dropoff_longitude: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub dropoff_notes: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub dropoff_seller_notes: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub dropoff_verification: Option<VerificationRequirement>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub manifest_reference: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub manifest_total_value: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pickup_business_name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pickup_latitude: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pickup_longitude: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pickup_notes: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pickup_verification: Option<VerificationRequirement>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub quote_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub undeliverable_action: Option<i8>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pickup_ready_dt: Option<LocalDateTime>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pickup_deadline_dt: Option<LocalDateTime>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub dropoff_ready_dt: Option<LocalDateTime>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub dropoff_deadline_dt: Option<LocalDateTime>,
    //#[serde(skip_serializing_if = "Option::is_none")]
    //pub requires_dropoff_signature: Option<bool>,
    //#[serde(skip_serializing_if = "Option::is_none")]
    //pub requires_id: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tip: Option<u32>,
    //#[serde(skip_serializing_if = "Option::is_none")]
    //pub idempotency_key: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub external_store_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub return_verification: Option<VerificationRequirement>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub test_specifications: Option<TestSpecifications>,
}

#[derive(Deserialize, Debug)]
#[serde(rename_all = "snake_case")]
pub struct CreateDeliveryResponse {
    pub complete: Option<bool>,
    pub courier: Option<CourierInfo>,
    pub courier_imminent: Option<bool>,
    pub created: Option<LocalDateTime>,
    pub currency: Option<String>,
    pub dropoff: Option<WaypointInfo>,
    pub dropoff_deadline: Option<LocalDateTime>,
    pub dropoff_eta: Option<LocalDateTime>,
    pub dropoff_identifier: Option<String>,
    pub dropoff_ready: Option<LocalDateTime>,
    pub external_id: Option<String>,
    pub fee: Option<u32>,
    pub id: Option<String>,
    pub kind: Option<String>,
    pub live_mode: Option<bool>,
    pub manifest: Option<ManifestInfo>,
    pub manifest_items:	Option<Vec<ManifestItem>>,
    pub pickup:	Option<WaypointInfo>,
    pub pickup_deadline: Option<LocalDateTime>,
    pub pickup_eta: Option<LocalDateTime>,
    pub pickup_ready: Option<LocalDateTime>,
    pub quote_id: Option<String>,
    pub related_deliveries: Option<Vec<RelatedDelivery>>,
    pub status: Option<String>,
    pub tip: Option<u32>,
    pub tracking_url: Option<String>,
    pub undeliverable_action: Option<String>,
    pub undeliverable_reason: Option<String>,
    pub updated: Option<LocalDateTime>,
    pub uuid: Option<String>,
    #[serde(rename = "return")]
    pub return_waypoint: Option<WaypointInfo>,
}

impl CreateDeliveryRequest {
    pub fn new<T: Into<String>>(
        dropoff_address: StructuredAddress, 
        dropoff_name: T, 
        dropoff_phone_number: T, 
        //manifest: T, 
        manifest_items: Vec<ManifestItem>, 
        pickup_address: StructuredAddress, 
        pickup_name: T, 
        pickup_phone_number: T) -> Self {
        CreateDeliveryRequest {
            dropoff_address: dropoff_address.to_string(),
            dropoff_name: dropoff_name.into(),
            dropoff_phone_number: dropoff_phone_number.into(),
            //manifest: manifest.into(),
            manifest_items,
            pickup_address: pickup_address.to_string(),
            pickup_name: pickup_name.into(),
            pickup_phone_number: pickup_phone_number.into(),
            ..Default::default()
        }
    }
    pub fn new_with_test<T: Into<String>>(
        dropoff_address: StructuredAddress, 
        dropoff_name: T, 
        dropoff_phone_number: T, 
        //manifest: T, 
        manifest_items: Vec<ManifestItem>, 
        pickup_address: StructuredAddress, 
        pickup_name: T, 
        pickup_phone_number: T,
        test_specifications: TestSpecifications) -> Self {
        CreateDeliveryRequest {
            dropoff_address: dropoff_address.to_string(),
            dropoff_name: dropoff_name.into(),
            dropoff_phone_number: dropoff_phone_number.into(),
            //manifest: manifest.into(),
            manifest_items,
            pickup_address: pickup_address.to_string(),
            pickup_name: pickup_name.into(),
            pickup_phone_number: pickup_phone_number.into(),
            test_specifications: Some(test_specifications),
            ..Default::default()
        }
    }
}

// confirm the three basic different types - based on Zulzi use case
pub enum CreateDeliveryRequestTypes {
    StandardDelivery {
        dropoff_address: StructuredAddress, 
        dropoff_name: String, 
        dropoff_phone_number: String, 
        //manifest: String, 
        manifest_items: Vec<ManifestItem>, 
        pickup_address: StructuredAddress, 
        pickup_name: String, 
        pickup_phone_number: String
    },
    VerifiableDelivery {
        dropoff_address: StructuredAddress, 
        dropoff_name: String, 
        dropoff_phone_number: String, 
        //manifest: String, 
        manifest_items: Vec<ManifestItem>, 
        pickup_address: StructuredAddress, 
        pickup_name: String, 
        pickup_phone_number: String,
        dropoff_verification: VerificationRequirement
    },
    ReturnableDelivery {
        dropoff_address: StructuredAddress, 
        dropoff_name: String, 
        dropoff_phone_number: String, 
        //manifest: String, 
        manifest_items: Vec<ManifestItem>, 
        pickup_address: StructuredAddress, 
        pickup_name: String, 
        pickup_phone_number: String,
        dropoff_verification: VerificationRequirement,
        return_verification: VerificationRequirement
    },
}
impl Into<CreateDeliveryRequest> for CreateDeliveryRequestTypes {
    fn into(self) -> CreateDeliveryRequest {
        match self {
            CreateDeliveryRequestTypes::StandardDelivery {
                dropoff_address, 
                dropoff_name, 
                dropoff_phone_number, 
                //manifest, 
                manifest_items, 
                pickup_address, 
                pickup_name, 
                pickup_phone_number } => {
                    CreateDeliveryRequest {
                        dropoff_address: dropoff_address.to_string(), 
                        dropoff_name, 
                        dropoff_phone_number, 
                        //manifest, 
                        manifest_items, 
                        pickup_address: pickup_address.to_string(), 
                        pickup_name, 
                        pickup_phone_number,
                        ..Default::default()
                    }
            },
            CreateDeliveryRequestTypes::VerifiableDelivery { 
                dropoff_address, 
                dropoff_name, 
                dropoff_phone_number,
                //manifest,
                manifest_items, 
                pickup_address,
                pickup_name, 
                pickup_phone_number,
                dropoff_verification } => {
                    CreateDeliveryRequest {
                        dropoff_address: dropoff_address.to_string(),
                        dropoff_name, 
                        dropoff_phone_number, 
                        //manifest, 
                        manifest_items, 
                        pickup_address: pickup_address.to_string(),
                        pickup_name, 
                        pickup_phone_number,
                        dropoff_verification: Some(dropoff_verification),
                        ..Default::default()
                    }
            },
            CreateDeliveryRequestTypes::ReturnableDelivery { 
                dropoff_address, 
                dropoff_name, 
                dropoff_phone_number,
                //manifest,
                manifest_items, 
                pickup_address,
                pickup_name, 
                pickup_phone_number,
                dropoff_verification,
                return_verification} => {
                    CreateDeliveryRequest {
                        dropoff_address: dropoff_address.to_string(), 
                        dropoff_name, 
                        dropoff_phone_number, 
                        //manifest, 
                        manifest_items, 
                        pickup_address: pickup_address.to_string(), 
                        pickup_name, 
                        pickup_phone_number,
                        dropoff_verification: Some(dropoff_verification),
                        return_verification: Some(return_verification),
                        ..Default::default()
                    }
            }
        }
    }
}