1#![allow(clippy::too_many_arguments)]
13
14use crate::client::Ghl;
15use crate::error::Result;
16use ghl_models::v2::store as models;
17
18#[derive(Debug, Clone)]
21pub struct StoreService {
22 pub(crate) client: Ghl,
23}
24
25impl StoreService {
26 pub(crate) fn new(client: Ghl) -> Self {
27 Self { client }
28 }
29}
30
31#[derive(Debug, Clone, Default)]
33pub struct ListShippingCarriersParams {
34 pub alt_id: String,
37 pub alt_type: String,
41}
42
43impl ListShippingCarriersParams {
44 pub fn new(alt_id: impl Into<String>, alt_type: impl Into<String>) -> Self {
46 Self {
47 alt_id: alt_id.into(),
48 alt_type: alt_type.into(),
49 }
50 }
51
52 fn to_query(&self) -> Vec<(String, String)> {
53 let q: Vec<(String, String)> = vec![
54 ("altId".into(), self.alt_id.clone()),
55 ("altType".into(), self.alt_type.clone()),
56 ];
57 q
58 }
59}
60
61#[derive(Debug, Clone, Default)]
63pub struct DeleteShippingCarrierParams {
64 pub alt_id: String,
67 pub alt_type: String,
71}
72
73impl DeleteShippingCarrierParams {
74 pub fn new(alt_id: impl Into<String>, alt_type: impl Into<String>) -> Self {
76 Self {
77 alt_id: alt_id.into(),
78 alt_type: alt_type.into(),
79 }
80 }
81
82 fn to_query(&self) -> Vec<(String, String)> {
83 let q: Vec<(String, String)> = vec![
84 ("altId".into(), self.alt_id.clone()),
85 ("altType".into(), self.alt_type.clone()),
86 ];
87 q
88 }
89}
90
91#[derive(Debug, Clone, Default)]
93pub struct GetShippingCarrierParams {
94 pub alt_id: String,
97 pub alt_type: String,
101}
102
103impl GetShippingCarrierParams {
104 pub fn new(alt_id: impl Into<String>, alt_type: impl Into<String>) -> Self {
106 Self {
107 alt_id: alt_id.into(),
108 alt_type: alt_type.into(),
109 }
110 }
111
112 fn to_query(&self) -> Vec<(String, String)> {
113 let q: Vec<(String, String)> = vec![
114 ("altId".into(), self.alt_id.clone()),
115 ("altType".into(), self.alt_type.clone()),
116 ];
117 q
118 }
119}
120
121#[derive(Debug, Clone, Default)]
123pub struct ListShippingZonesParams {
124 pub alt_id: String,
127 pub alt_type: String,
131 pub limit: Option<f64>,
133 pub offset: Option<f64>,
136 pub with_shipping_rate: Option<bool>,
138}
139
140impl ListShippingZonesParams {
141 pub fn new(alt_id: impl Into<String>, alt_type: impl Into<String>) -> Self {
143 Self {
144 alt_id: alt_id.into(),
145 alt_type: alt_type.into(),
146 ..Default::default()
147 }
148 }
149
150 pub fn limit(mut self, v: f64) -> Self {
152 self.limit = Some(v);
153 self
154 }
155
156 pub fn offset(mut self, v: f64) -> Self {
159 self.offset = Some(v);
160 self
161 }
162
163 pub fn with_shipping_rate(mut self, v: bool) -> Self {
165 self.with_shipping_rate = Some(v);
166 self
167 }
168
169 fn to_query(&self) -> Vec<(String, String)> {
170 let mut q: Vec<(String, String)> = vec![
171 ("altId".into(), self.alt_id.clone()),
172 ("altType".into(), self.alt_type.clone()),
173 ];
174 if let Some(v) = &self.limit {
175 q.push(("limit".into(), v.to_string()));
176 }
177 if let Some(v) = &self.offset {
178 q.push(("offset".into(), v.to_string()));
179 }
180 if let Some(v) = &self.with_shipping_rate {
181 q.push(("withShippingRate".into(), v.to_string()));
182 }
183 q
184 }
185}
186
187#[derive(Debug, Clone, Default)]
189pub struct DeleteShippingZoneParams {
190 pub alt_id: String,
193 pub alt_type: String,
197}
198
199impl DeleteShippingZoneParams {
200 pub fn new(alt_id: impl Into<String>, alt_type: impl Into<String>) -> Self {
202 Self {
203 alt_id: alt_id.into(),
204 alt_type: alt_type.into(),
205 }
206 }
207
208 fn to_query(&self) -> Vec<(String, String)> {
209 let q: Vec<(String, String)> = vec![
210 ("altId".into(), self.alt_id.clone()),
211 ("altType".into(), self.alt_type.clone()),
212 ];
213 q
214 }
215}
216
217#[derive(Debug, Clone, Default)]
219pub struct GetShippingZoneParams {
220 pub alt_id: String,
223 pub alt_type: String,
227 pub with_shipping_rate: Option<bool>,
229}
230
231impl GetShippingZoneParams {
232 pub fn new(alt_id: impl Into<String>, alt_type: impl Into<String>) -> Self {
234 Self {
235 alt_id: alt_id.into(),
236 alt_type: alt_type.into(),
237 ..Default::default()
238 }
239 }
240
241 pub fn with_shipping_rate(mut self, v: bool) -> Self {
243 self.with_shipping_rate = Some(v);
244 self
245 }
246
247 fn to_query(&self) -> Vec<(String, String)> {
248 let mut q: Vec<(String, String)> = vec![
249 ("altId".into(), self.alt_id.clone()),
250 ("altType".into(), self.alt_type.clone()),
251 ];
252 if let Some(v) = &self.with_shipping_rate {
253 q.push(("withShippingRate".into(), v.to_string()));
254 }
255 q
256 }
257}
258
259#[derive(Debug, Clone, Default)]
261pub struct ListShippingRatesParams {
262 pub alt_id: String,
265 pub alt_type: String,
269 pub limit: Option<f64>,
271 pub offset: Option<f64>,
274}
275
276impl ListShippingRatesParams {
277 pub fn new(alt_id: impl Into<String>, alt_type: impl Into<String>) -> Self {
279 Self {
280 alt_id: alt_id.into(),
281 alt_type: alt_type.into(),
282 ..Default::default()
283 }
284 }
285
286 pub fn limit(mut self, v: f64) -> Self {
288 self.limit = Some(v);
289 self
290 }
291
292 pub fn offset(mut self, v: f64) -> Self {
295 self.offset = Some(v);
296 self
297 }
298
299 fn to_query(&self) -> Vec<(String, String)> {
300 let mut q: Vec<(String, String)> = vec![
301 ("altId".into(), self.alt_id.clone()),
302 ("altType".into(), self.alt_type.clone()),
303 ];
304 if let Some(v) = &self.limit {
305 q.push(("limit".into(), v.to_string()));
306 }
307 if let Some(v) = &self.offset {
308 q.push(("offset".into(), v.to_string()));
309 }
310 q
311 }
312}
313
314#[derive(Debug, Clone, Default)]
316pub struct DeleteShippingRateParams {
317 pub alt_id: String,
320 pub alt_type: String,
324}
325
326impl DeleteShippingRateParams {
327 pub fn new(alt_id: impl Into<String>, alt_type: impl Into<String>) -> Self {
329 Self {
330 alt_id: alt_id.into(),
331 alt_type: alt_type.into(),
332 }
333 }
334
335 fn to_query(&self) -> Vec<(String, String)> {
336 let q: Vec<(String, String)> = vec![
337 ("altId".into(), self.alt_id.clone()),
338 ("altType".into(), self.alt_type.clone()),
339 ];
340 q
341 }
342}
343
344#[derive(Debug, Clone, Default)]
346pub struct GetShippingRateParams {
347 pub alt_id: String,
350 pub alt_type: String,
354}
355
356impl GetShippingRateParams {
357 pub fn new(alt_id: impl Into<String>, alt_type: impl Into<String>) -> Self {
359 Self {
360 alt_id: alt_id.into(),
361 alt_type: alt_type.into(),
362 }
363 }
364
365 fn to_query(&self) -> Vec<(String, String)> {
366 let q: Vec<(String, String)> = vec![
367 ("altId".into(), self.alt_id.clone()),
368 ("altType".into(), self.alt_type.clone()),
369 ];
370 q
371 }
372}
373
374#[derive(Debug, Clone, Default)]
376pub struct GetStoreSettingsParams {
377 pub alt_id: String,
380 pub alt_type: String,
384}
385
386impl GetStoreSettingsParams {
387 pub fn new(alt_id: impl Into<String>, alt_type: impl Into<String>) -> Self {
389 Self {
390 alt_id: alt_id.into(),
391 alt_type: alt_type.into(),
392 }
393 }
394
395 fn to_query(&self) -> Vec<(String, String)> {
396 let q: Vec<(String, String)> = vec![
397 ("altId".into(), self.alt_id.clone()),
398 ("altType".into(), self.alt_type.clone()),
399 ];
400 q
401 }
402}
403
404impl StoreService {
405 pub async fn list_shipping_carriers(
411 &self,
412 params: &ListShippingCarriersParams,
413 ) -> Result<models::ListShippingCarrierResponseDto> {
414 let query = params.to_query();
415 self.client
416 .send_versioned(
417 reqwest::Method::GET,
418 "/store/shipping-carrier",
419 &query,
420 None::<&()>,
421 None,
422 )
423 .await
424 }
425
426 pub async fn create_shipping_carrier(
432 &self,
433 body: &models::CreateShippingCarrierDto,
434 ) -> Result<models::CreateShippingCarrierResponseDto> {
435 let query = Vec::new();
436 self.client
437 .send_versioned(
438 reqwest::Method::POST,
439 "/store/shipping-carrier",
440 &query,
441 Some(body),
442 None,
443 )
444 .await
445 }
446
447 pub async fn delete_shipping_carrier(
453 &self,
454 shipping_carrier_id: &str,
455 params: &DeleteShippingCarrierParams,
456 ) -> Result<models::DeleteShippingCarrierResponseDto> {
457 let path = format!(
458 "/store/shipping-carrier/{}",
459 crate::services::encode(shipping_carrier_id)
460 );
461 let query = params.to_query();
462 self.client
463 .send_versioned(reqwest::Method::DELETE, &path, &query, None::<&()>, None)
464 .await
465 }
466
467 pub async fn get_shipping_carrier(
474 &self,
475 shipping_carrier_id: &str,
476 params: &GetShippingCarrierParams,
477 ) -> Result<models::GetShippingCarrierResponseDto> {
478 let path = format!(
479 "/store/shipping-carrier/{}",
480 crate::services::encode(shipping_carrier_id)
481 );
482 let query = params.to_query();
483 self.client
484 .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, None)
485 .await
486 }
487
488 pub async fn update_shipping_carrier(
494 &self,
495 shipping_carrier_id: &str,
496 body: &models::UpdateShippingCarrierDto,
497 ) -> Result<models::UpdateShippingCarrierResponseDto> {
498 let path = format!(
499 "/store/shipping-carrier/{}",
500 crate::services::encode(shipping_carrier_id)
501 );
502 let query = Vec::new();
503 self.client
504 .send_versioned(reqwest::Method::PUT, &path, &query, Some(body), None)
505 .await
506 }
507
508 pub async fn list_shipping_zones(
514 &self,
515 params: &ListShippingZonesParams,
516 ) -> Result<models::ListShippingZoneResponseDto> {
517 let query = params.to_query();
518 self.client
519 .send_versioned(
520 reqwest::Method::GET,
521 "/store/shipping-zone",
522 &query,
523 None::<&()>,
524 None,
525 )
526 .await
527 }
528
529 pub async fn create_shipping_zone(
535 &self,
536 body: &models::CreateShippingZoneDto,
537 ) -> Result<models::CreateShippingZoneResponseDto> {
538 let query = Vec::new();
539 self.client
540 .send_versioned(
541 reqwest::Method::POST,
542 "/store/shipping-zone",
543 &query,
544 Some(body),
545 None,
546 )
547 .await
548 }
549
550 pub async fn get_available_shipping_rates(
556 &self,
557 body: &models::GetAvailableShippingRates,
558 ) -> Result<models::GetAvailableShippingRatesResponseDto> {
559 let query = Vec::new();
560 self.client
561 .send_versioned(
562 reqwest::Method::POST,
563 "/store/shipping-zone/shipping-rates",
564 &query,
565 Some(body),
566 None,
567 )
568 .await
569 }
570
571 pub async fn delete_shipping_zone(
577 &self,
578 shipping_zone_id: &str,
579 params: &DeleteShippingZoneParams,
580 ) -> Result<models::DeleteShippingZoneResponseDto> {
581 let path = format!(
582 "/store/shipping-zone/{}",
583 crate::services::encode(shipping_zone_id)
584 );
585 let query = params.to_query();
586 self.client
587 .send_versioned(reqwest::Method::DELETE, &path, &query, None::<&()>, None)
588 .await
589 }
590
591 pub async fn get_shipping_zone(
597 &self,
598 shipping_zone_id: &str,
599 params: &GetShippingZoneParams,
600 ) -> Result<models::GetShippingZoneResponseDto> {
601 let path = format!(
602 "/store/shipping-zone/{}",
603 crate::services::encode(shipping_zone_id)
604 );
605 let query = params.to_query();
606 self.client
607 .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, None)
608 .await
609 }
610
611 pub async fn update_shipping_zone(
617 &self,
618 shipping_zone_id: &str,
619 body: &models::UpdateShippingZoneDto,
620 ) -> Result<models::UpdateShippingZoneResponseDto> {
621 let path = format!(
622 "/store/shipping-zone/{}",
623 crate::services::encode(shipping_zone_id)
624 );
625 let query = Vec::new();
626 self.client
627 .send_versioned(reqwest::Method::PUT, &path, &query, Some(body), None)
628 .await
629 }
630
631 pub async fn list_shipping_rates(
637 &self,
638 shipping_zone_id: &str,
639 params: &ListShippingRatesParams,
640 ) -> Result<models::ListShippingRateResponseDto> {
641 let path = format!(
642 "/store/shipping-zone/{}/shipping-rate",
643 crate::services::encode(shipping_zone_id)
644 );
645 let query = params.to_query();
646 self.client
647 .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, None)
648 .await
649 }
650
651 pub async fn create_shipping_rate(
657 &self,
658 shipping_zone_id: &str,
659 body: &models::CreateShippingRateDto,
660 ) -> Result<models::CreateShippingRateResponseDto> {
661 let path = format!(
662 "/store/shipping-zone/{}/shipping-rate",
663 crate::services::encode(shipping_zone_id)
664 );
665 let query = Vec::new();
666 self.client
667 .send_versioned(reqwest::Method::POST, &path, &query, Some(body), None)
668 .await
669 }
670
671 pub async fn delete_shipping_rate(
677 &self,
678 shipping_zone_id: &str,
679 shipping_rate_id: &str,
680 params: &DeleteShippingRateParams,
681 ) -> Result<models::DeleteShippingRateResponseDto> {
682 let path = format!(
683 "/store/shipping-zone/{}/shipping-rate/{}",
684 crate::services::encode(shipping_zone_id),
685 crate::services::encode(shipping_rate_id)
686 );
687 let query = params.to_query();
688 self.client
689 .send_versioned(reqwest::Method::DELETE, &path, &query, None::<&()>, None)
690 .await
691 }
692
693 pub async fn get_shipping_rate(
699 &self,
700 shipping_zone_id: &str,
701 shipping_rate_id: &str,
702 params: &GetShippingRateParams,
703 ) -> Result<models::GetShippingRateResponseDto> {
704 let path = format!(
705 "/store/shipping-zone/{}/shipping-rate/{}",
706 crate::services::encode(shipping_zone_id),
707 crate::services::encode(shipping_rate_id)
708 );
709 let query = params.to_query();
710 self.client
711 .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, None)
712 .await
713 }
714
715 pub async fn update_shipping_rate(
721 &self,
722 shipping_zone_id: &str,
723 shipping_rate_id: &str,
724 body: &models::UpdateShippingRateDto,
725 ) -> Result<models::UpdateShippingRateResponseDto> {
726 let path = format!(
727 "/store/shipping-zone/{}/shipping-rate/{}",
728 crate::services::encode(shipping_zone_id),
729 crate::services::encode(shipping_rate_id)
730 );
731 let query = Vec::new();
732 self.client
733 .send_versioned(reqwest::Method::PUT, &path, &query, Some(body), None)
734 .await
735 }
736
737 pub async fn get_store_settings(
743 &self,
744 params: &GetStoreSettingsParams,
745 ) -> Result<models::GetStoreSettingResponseDto> {
746 let query = params.to_query();
747 self.client
748 .send_versioned(
749 reqwest::Method::GET,
750 "/store/store-setting",
751 &query,
752 None::<&()>,
753 None,
754 )
755 .await
756 }
757
758 pub async fn create_update_store_settings(
764 &self,
765 body: &models::CreateStoreSettingDto,
766 ) -> Result<models::CreateStoreSettingResponseDto> {
767 let query = Vec::new();
768 self.client
769 .send_versioned(
770 reqwest::Method::POST,
771 "/store/store-setting",
772 &query,
773 Some(body),
774 None,
775 )
776 .await
777 }
778}