tfl_api_wrapper/
line.rs

1use crate::{
2    linemodels::{self},
3    models::{self},
4    request::create_endpoint,
5    Client, RequestBuilder,
6};
7
8create_endpoint!(RouteRequest);
9
10impl RequestBuilder for RouteRequest<'_> {
11    type Response = models::Line;
12
13    fn get_client(&self) -> &Client {
14        self.client
15    }
16
17    fn get_parameters(&self) -> &models::Parameters {
18        &self.parameters
19    }
20
21    fn get_request_url(&self) -> String {
22        format!("/Line/Route?{:?}", self.get_parameters().service_type)
23    }
24}
25
26impl RouteRequest<'_> {
27    pub fn service_type(mut self, service_types: models::ServiceTypes) -> Self {
28        self.parameters.service_type = Some(service_types.to_type().to_string());
29        self
30    }
31}
32
33create_endpoint!(RouteRequestById);
34
35impl RequestBuilder for RouteRequestById<'_> {
36    type Response = models::Lines;
37
38    fn get_client(&self) -> &Client {
39        self.client
40    }
41
42    fn get_parameters(&self) -> &models::Parameters {
43        &self.parameters
44    }
45
46    fn get_request_url(&self) -> String {
47        format!(
48            "/Line/{}/Route?{:?}",
49            self.get_parameters().lines,
50            self.get_parameters().service_type
51        )
52    }
53}
54
55impl RouteRequestById<'_> {
56    // filter by line ids
57    pub fn line(mut self, line: Vec<linemodels::LineID>) -> Self {
58        let mut lines: String = "".to_owned();
59        for k in line {
60            //k.line().to_string();
61            if lines == "" {
62                lines.push_str(k.line().into());
63            } else {
64                lines.push_str(",");
65                lines.push_str(k.line().into());
66            }
67        }
68        self.parameters.lines = lines;
69        self
70    }
71
72    pub fn service_type(mut self, service_types: models::ServiceTypes) -> Self {
73        self.parameters.service_type = Some(service_types.to_type().to_string());
74        self
75    }
76}
77
78create_endpoint!(DisruptionByMode);
79
80impl RequestBuilder for DisruptionByMode<'_> {
81    type Response = models::Disruption;
82
83    fn get_client(&self) -> &Client {
84        self.client
85    }
86
87    fn get_parameters(&self) -> &models::Parameters {
88        &self.parameters
89    }
90
91    fn get_request_url(&self) -> String {
92        format!("/Line/Mode/{}/Disruption", self.get_parameters().modes)
93    }
94}
95
96impl DisruptionByMode<'_> {
97    // Get disruption for all lines by mode
98    pub fn mode(mut self, mode: Vec<models::Mode>) -> Self {
99        let mut modes: String = "".to_owned();
100        for k in mode {
101            //k.line().to_string();
102            if modes == "" {
103                modes.push_str(k.mode().into());
104            } else {
105                modes.push_str(",");
106                modes.push_str(k.mode().into());
107            }
108        }
109        self.parameters.modes = modes;
110        self
111    }
112}
113
114create_endpoint!(DisruptionByLines);
115
116impl RequestBuilder for DisruptionByLines<'_> {
117    type Response = models::Disruption;
118
119    fn get_client(&self) -> &Client {
120        self.client
121    }
122
123    fn get_parameters(&self) -> &models::Parameters {
124        &self.parameters
125    }
126
127    fn get_request_url(&self) -> String {
128        format!("/Line/{}/Disruption", self.get_parameters().lines)
129    }
130}
131
132impl DisruptionByLines<'_> {
133    // filter by line
134    pub fn line(mut self, line: Vec<linemodels::LineID>) -> Self {
135        let mut lines: String = "".to_owned();
136        for k in line {
137            //k.line().to_string();
138            if lines == "" {
139                lines.push_str(k.line().into());
140            } else {
141                lines.push_str(",");
142                lines.push_str(k.line().into());
143            }
144        }
145        self.parameters.lines = lines;
146        self
147    }
148}
149
150create_endpoint!(ArrivalPredictionsByLines);
151
152impl RequestBuilder for ArrivalPredictionsByLines<'_> {
153    type Response = models::Arrival;
154
155    fn get_client(&self) -> &Client {
156        self.client
157    }
158
159    fn get_parameters(&self) -> &models::Parameters {
160        &self.parameters
161    }
162
163    fn get_request_url(&self) -> String {
164        format!("/Line/{}/Arrivals", self.get_parameters().lines)
165    }
166}
167
168impl ArrivalPredictionsByLines<'_> {
169    // filter by line
170    pub fn line(mut self, line: Vec<linemodels::LineID>) -> Self {
171        let mut lines: String = "".to_owned();
172        for k in line {
173            //k.line().to_string();
174            if lines == "" {
175                lines.push_str(k.line().into());
176            } else {
177                lines.push_str(",");
178                lines.push_str(k.line().into());
179            }
180        }
181        self.parameters.lines = lines;
182        self
183    }
184}
185
186create_endpoint!(ArrivalPredictionsByLinesStopPointID);
187
188impl RequestBuilder for ArrivalPredictionsByLinesStopPointID<'_> {
189    type Response = models::Arrival;
190
191    fn get_client(&self) -> &Client {
192        self.client
193    }
194
195    fn get_parameters(&self) -> &models::Parameters {
196        &self.parameters
197    }
198
199    fn get_request_url(&self) -> String {
200        if !self.get_parameters().stop_point_id.is_empty() {
201            if self.get_parameters().direction.is_none()
202                && self.get_parameters().destination_station_id.is_none()
203            {
204                format!(
205                    "/Line/{}/Arrivals/{}",
206                    self.get_parameters().lines,
207                    self.get_parameters().stop_point_id
208                )
209            } else if self.get_parameters().direction.is_some()
210                && self.get_parameters().destination_station_id.is_none()
211            {
212                format!(
213                    "/Line/{}/Arrivals/{}?{:?}",
214                    self.get_parameters().lines,
215                    self.get_parameters().stop_point_id,
216                    self.get_parameters().direction
217                )
218            } else {
219                format!(
220                    "/Line/{}/Arrivals/{}?{:?}",
221                    self.get_parameters().lines,
222                    self.get_parameters().stop_point_id,
223                    self.get_parameters().direction
224                )
225            }
226        } else {
227            format!(
228                "/Line/{}/Arrivals/{}",
229                self.get_parameters().lines,
230                self.get_parameters().stop_point_id
231            )
232        }
233    }
234}
235
236impl ArrivalPredictionsByLinesStopPointID<'_> {
237    // filter by line
238    pub fn line(mut self, line: Vec<linemodels::LineID>) -> Self {
239        let mut lines: String = "".to_owned();
240        for k in line {
241            //k.line().to_string();
242            if lines == "" {
243                lines.push_str(k.line().into());
244            } else {
245                lines.push_str(",");
246                lines.push_str(k.line().into());
247            }
248        }
249        self.parameters.lines = lines;
250        self
251    }
252
253    pub fn stop_point(mut self, stop_point_id: &str) -> Self {
254        self.parameters.stop_point_id = stop_point_id.to_string();
255        self
256    }
257
258    pub fn direction(mut self, direction: models::Directions) -> Self {
259        self.parameters.direction = Some(direction.to_type().to_string());
260        self
261    }
262
263    pub fn destination_station_id(mut self, destination_station_id: &str) -> Self {
264        self.parameters.destination_station_id = Some(destination_station_id.to_string());
265        self
266    }
267}
268
269create_endpoint!(ListStationsByLines);
270
271impl RequestBuilder for ListStationsByLines<'_> {
272    type Response = models::StopPoint;
273
274    fn get_client(&self) -> &Client {
275        self.client
276    }
277
278    fn get_parameters(&self) -> &models::Parameters {
279        &self.parameters
280    }
281
282    fn get_request_url(&self) -> String {
283        format!("/Line/{}/StopPoints?", self.get_parameters().lines)
284    }
285}
286
287impl ListStationsByLines<'_> {
288    // filter by line
289    pub fn line(mut self, line: Vec<linemodels::LineID>) -> Self {
290        let mut lines: String = "".to_owned();
291        for k in line {
292            //k.line().to_string();
293            if lines == "" {
294                lines.push_str(k.line().into());
295            } else {
296                lines.push_str(",");
297                lines.push_str(k.line().into());
298            }
299        }
300        self.parameters.lines = lines;
301        self
302    }
303
304    pub fn tfl_operated_national_rail_stations_only(
305        mut self,
306        tfl_operated_national_rail_stations_only: bool,
307    ) -> Self {
308        self.parameters.tfl_operated_national_rail_stations_only =
309            Some(tfl_operated_national_rail_stations_only);
310        self
311    }
312}
313
314create_endpoint!(ListDisruptionCategories);
315
316impl RequestBuilder for ListDisruptionCategories<'_> {
317    type Response = models::DisruptionCategories;
318
319    fn get_request_url(&self) -> String {
320        "/Line/Meta/DisruptionCategories".into()
321    }
322
323    fn get_parameters(&self) -> &models::Parameters {
324        &self.parameters
325    }
326
327    fn get_client(&self) -> &Client {
328        self.client
329    }
330}
331
332create_endpoint!(ListModes);
333
334impl RequestBuilder for ListModes<'_> {
335    type Response = models::Modes;
336
337    fn get_request_url(&self) -> String {
338        "/Line/Meta/Modes".into()
339    }
340
341    fn get_parameters(&self) -> &models::Parameters {
342        &self.parameters
343    }
344
345    fn get_client(&self) -> &Client {
346        self.client
347    }
348}
349
350create_endpoint!(ListServiceTypes);
351
352impl RequestBuilder for ListServiceTypes<'_> {
353    type Response = models::LServiceTypes;
354
355    fn get_request_url(&self) -> String {
356        "/Line/Meta/ServiceTypes".into()
357    }
358
359    fn get_parameters(&self) -> &models::Parameters {
360        &self.parameters
361    }
362
363    fn get_client(&self) -> &Client {
364        self.client
365    }
366}
367
368create_endpoint!(ListSeverityTypes);
369
370impl RequestBuilder for ListSeverityTypes<'_> {
371    type Response = models::Serverities;
372
373    fn get_request_url(&self) -> String {
374        "/Line/Meta/Severity".into()
375    }
376
377    fn get_parameters(&self) -> &models::Parameters {
378        &self.parameters
379    }
380
381    fn get_client(&self) -> &Client {
382        self.client
383    }
384}
385
386create_endpoint!(ListLinesRoutesByModes);
387
388impl RequestBuilder for ListLinesRoutesByModes<'_> {
389    type Response = models::Line;
390
391    fn get_request_url(&self) -> String {
392        format!(
393            "/Line/Mode/{}/Route?{:?}",
394            self.get_parameters().modes,
395            self.get_parameters().service_type
396        )
397    }
398
399    fn get_parameters(&self) -> &models::Parameters {
400        &self.parameters
401    }
402
403    fn get_client(&self) -> &Client {
404        self.client
405    }
406}
407
408impl ListLinesRoutesByModes<'_> {
409    // Get disruption for all lines by mode
410    pub fn mode(mut self, mode: Vec<models::Mode>) -> Self {
411        let mut modes: String = "".to_owned();
412        for k in mode {
413            //k.line().to_string();
414            if modes == "" {
415                modes.push_str(k.mode().into());
416            } else {
417                modes.push_str(",");
418                modes.push_str(k.mode().into());
419            }
420        }
421        self.parameters.modes = modes;
422        self
423    }
424
425    pub fn service_type(mut self, service_types: models::ServiceTypes) -> Self {
426        self.parameters.service_type = Some(service_types.to_type().to_string());
427        self
428    }
429}
430
431create_endpoint!(ListRoutesForLineIDWithSequence);
432
433impl RequestBuilder for ListRoutesForLineIDWithSequence<'_> {
434    type Response = models::Routes;
435    fn get_parameters(&self) -> &models::Parameters {
436        &self.parameters
437    }
438
439    fn get_request_url(&self) -> String {
440        if self.get_parameters().direction.is_some() {
441            if self.get_parameters().service_type.is_some()
442                && self.get_parameters().exclude_crowding.is_some()
443            {
444                format!(
445                    "/Line/{}/Route/Sequence/{}?{}&excludeCrowding={}",
446                    self.get_parameters().line_id,
447                    self.get_parameters().direction.as_ref().unwrap(),
448                    self.get_parameters().service_type.as_ref().unwrap(),
449                    self.get_parameters().exclude_crowding.as_ref().unwrap()
450                )
451            } else if self.get_parameters().service_type.is_some()
452                && self.get_parameters().exclude_crowding.is_none()
453            {
454                format!(
455                    "/Line/{}/Route/Sequence/{}/?{}",
456                    self.get_parameters().line_id,
457                    self.get_parameters().direction.as_ref().unwrap(),
458                    self.get_parameters().service_type.as_ref().unwrap()
459                )
460            } else if self.get_parameters().service_type.is_none()
461                && self.get_parameters().exclude_crowding.is_some()
462            {
463                format!(
464                    "/Line/{}/Route/Sequence/{}?excludeCrowding={}",
465                    self.get_parameters().line_id,
466                    self.get_parameters().direction.as_ref().unwrap(),
467                    self.get_parameters().exclude_crowding.as_ref().unwrap()
468                )
469            } else {
470                format!(
471                    "/Line/{}/Route/Sequence/{}",
472                    self.get_parameters().line_id,
473                    self.get_parameters().direction.as_ref().unwrap(),
474                )
475            }
476        } else {
477            format!("/Line/{}/Route/Sequence/All", self.get_parameters().line_id)
478        }
479    }
480
481    fn get_client(&self) -> &Client {
482        self.client
483    }
484}
485
486impl ListRoutesForLineIDWithSequence<'_> {
487    // Get line id
488    pub fn line(mut self, id: linemodels::LineID) -> Self {
489        self.parameters.line_id = id.line().to_string();
490        self
491    }
492
493    pub fn service_type(mut self, service_type: models::ServiceTypes) -> Self {
494        self.parameters.service_type = Some(service_type.to_type().to_string());
495        self
496    }
497    pub fn exclude_crowding(mut self, exclude_crowding: bool) -> Self {
498        self.parameters.exclude_crowding = Some(exclude_crowding);
499        self
500    }
501
502    /// direction of line
503    pub fn direction(mut self, direction: models::Directions) -> Self {
504        self.parameters.direction = Some(direction.to_type().to_string());
505        self
506    }
507}
508
509create_endpoint!(ListLinesByID);
510
511impl RequestBuilder for ListLinesByID<'_> {
512    type Response = models::Line;
513
514    fn get_request_url(&self) -> String {
515        format!("/Line/{}", self.get_parameters().lines)
516    }
517
518    fn get_parameters(&self) -> &models::Parameters {
519        &self.parameters
520    }
521
522    fn get_client(&self) -> &Client {
523        self.client
524    }
525}
526
527impl ListLinesByID<'_> {
528    // filter by line
529    pub fn line(mut self, line: Vec<linemodels::LineID>) -> Self {
530        let mut lines: String = "".to_owned();
531        for k in line {
532            //k.line().to_string();
533            if lines == "" {
534                lines.push_str(k.line().into());
535            } else {
536                lines.push_str(",");
537                lines.push_str(k.line().into());
538            }
539        }
540        self.parameters.lines = lines;
541        self
542    }
543}
544
545create_endpoint!(ListLinesByModes);
546
547impl RequestBuilder for ListLinesByModes<'_> {
548    type Response = models::Line;
549
550    fn get_request_url(&self) -> String {
551        format!("/Line/Mode/{}", self.get_parameters().modes)
552    }
553
554    fn get_parameters(&self) -> &models::Parameters {
555        &self.parameters
556    }
557
558    fn get_client(&self) -> &Client {
559        self.client
560    }
561}
562
563impl ListLinesByModes<'_> {
564    // Get disruption for all lines by mode
565    pub fn mode(mut self, mode: Vec<models::Mode>) -> Self {
566        let mut modes: String = "".to_owned();
567        for k in mode {
568            //k.line().to_string();
569            if modes == "" {
570                modes.push_str(k.mode().into());
571            } else {
572                modes.push_str(",");
573                modes.push_str(k.mode().into());
574            }
575        }
576        self.parameters.modes = modes;
577        self
578    }
579}
580
581create_endpoint!(LineStatusBySeverity);
582
583impl RequestBuilder for LineStatusBySeverity<'_> {
584    type Response = models::LineSeverity;
585
586    fn get_request_url(&self) -> String {
587        format!(
588            "/Line/Status/{}",
589            self.get_parameters().severity.as_ref().unwrap()
590        )
591    }
592
593    fn get_parameters(&self) -> &models::Parameters {
594        &self.parameters
595    }
596
597    fn get_client(&self) -> &Client {
598        self.client
599    }
600}
601
602impl LineStatusBySeverity<'_> {
603    // Get disruption for all lines by mode
604    pub fn level(mut self, sev: i8) -> Self {
605        self.parameters.severity = Some(sev);
606        self
607    }
608}
609
610create_endpoint!(LineStatusBetweenDates);
611
612impl RequestBuilder for LineStatusBetweenDates<'_> {
613    type Response = models::LineStatusBetweenDates;
614
615    fn get_request_url(&self) -> String {
616        if self.get_parameters().detail.is_some() {
617            format!(
618                "/Line/{}/Status/{}/to/{}?detail={}",
619                self.get_parameters().lines,
620                self.get_parameters().start_date,
621                self.get_parameters().end_date,
622                self.get_parameters().detail.as_ref().unwrap()
623            )
624        } else {
625            format!(
626                "/Line/{}/Status/{}/to/{}",
627                self.get_parameters().lines,
628                self.get_parameters().start_date,
629                self.get_parameters().end_date
630            )
631        }
632    }
633
634    fn get_parameters(&self) -> &models::Parameters {
635        &self.parameters
636    }
637
638    fn get_client(&self) -> &Client {
639        self.client
640    }
641}
642
643impl LineStatusBetweenDates<'_> {
644    // filter by line
645    pub fn line(mut self, line: Vec<linemodels::LineID>) -> Self {
646        let mut lines: String = "".to_owned();
647        for k in line {
648            //k.line().to_string();
649            if lines == "" {
650                lines.push_str(k.line().into());
651            } else {
652                lines.push_str(",");
653                lines.push_str(k.line().into());
654            }
655        }
656        self.parameters.lines = lines;
657        self
658    }
659
660    // Start date
661    pub fn start_date(mut self, start_date: &str) -> Self {
662        self.parameters.start_date = start_date.to_string();
663        self
664    }
665
666    // End date
667    pub fn end_date(mut self, end_date: &str) -> Self {
668        self.parameters.end_date = end_date.to_string();
669        self
670    }
671
672    // detail
673    pub fn detail(mut self, detail: bool) -> Self {
674        self.parameters.detail = Some(detail);
675        self
676    }
677}
678
679create_endpoint!(LineStatusByModes);
680
681impl RequestBuilder for LineStatusByModes<'_> {
682    type Response = models::LineStatusForModes;
683
684    fn get_request_url(&self) -> String {
685        if self.get_parameters().detail.is_some() && self.get_parameters().severity.is_some() {
686            format!(
687                "/Line/Mode/{}/Status?detail={}&severityLevel={}",
688                self.get_parameters().modes,
689                self.get_parameters().detail.as_ref().unwrap(),
690                self.get_parameters().severity.as_ref().unwrap()
691            )
692        } else if self.get_parameters().detail.is_none() && self.get_parameters().severity.is_some()
693        {
694            format!(
695                "/Line/Mode/{}/Status?severityLevel={}",
696                self.get_parameters().modes,
697                self.get_parameters().severity.as_ref().unwrap()
698            )
699        } else {
700            format!("/Line/Mode/{}/Status", self.get_parameters().modes)
701        }
702    }
703
704    fn get_parameters(&self) -> &models::Parameters {
705        &self.parameters
706    }
707
708    fn get_client(&self) -> &Client {
709        self.client
710    }
711}
712
713impl LineStatusByModes<'_> {
714    // Get disruption for all lines by mode
715    pub fn mode(mut self, mode: Vec<models::Mode>) -> Self {
716        let mut modes: String = "".to_owned();
717        for k in mode {
718            //k.line().to_string();
719            if modes == "" {
720                modes.push_str(k.mode().into());
721            } else {
722                modes.push_str(",");
723                modes.push_str(k.mode().into());
724            }
725        }
726        self.parameters.modes = modes;
727        self
728    }
729
730    // detail
731    pub fn detail(mut self, detail: bool) -> Self {
732        self.parameters.detail = Some(detail);
733        self
734    }
735
736    pub fn severity(mut self, severity: i8) -> Self {
737        self.parameters.severity = Some(severity);
738        self
739    }
740}
741
742create_endpoint!(LineStatusByIDs);
743
744impl RequestBuilder for LineStatusByIDs<'_> {
745    type Response = models::LineStatusForModes;
746
747    fn get_request_url(&self) -> String {
748        if self.get_parameters().detail.is_some() {
749            format!(
750                "/Line/{}/Status?detail={}",
751                self.get_parameters().lines,
752                self.get_parameters().detail.as_ref().unwrap()
753            )
754        } else {
755            format!("/Line/{}/Status", self.get_parameters().lines)
756        }
757    }
758
759    fn get_parameters(&self) -> &models::Parameters {
760        &self.parameters
761    }
762
763    fn get_client(&self) -> &Client {
764        self.client
765    }
766}
767
768impl LineStatusByIDs<'_> {
769    // filter by line
770    pub fn line(mut self, line: Vec<linemodels::LineID>) -> Self {
771        let mut lines: String = "".to_owned();
772        for k in line {
773            //k.line().to_string();
774            if lines == "" {
775                lines.push_str(k.line().into());
776            } else {
777                lines.push_str(",");
778                lines.push_str(k.line().into());
779            }
780        }
781        self.parameters.lines = lines;
782        self
783    }
784
785    // detail
786    pub fn detail(mut self, detail: bool) -> Self {
787        self.parameters.detail = Some(detail);
788        self
789    }
790}
791
792create_endpoint!(StationTimetableByLine);
793
794impl RequestBuilder for StationTimetableByLine<'_> {
795    type Response = models::TimetableForStationByLineID;
796
797    fn get_request_url(&self) -> String {
798        format!(
799            "/Line/{}/Timetable/{}",
800            self.get_parameters().line_id,
801            self.get_parameters().stop_point_id
802        )
803    }
804
805    fn get_parameters(&self) -> &models::Parameters {
806        &self.parameters
807    }
808
809    fn get_client(&self) -> &Client {
810        self.client
811    }
812}
813
814impl StationTimetableByLine<'_> {
815    // Get line id
816    pub fn line(mut self, id: linemodels::LineID) -> Self {
817        self.parameters.line_id = id.line().to_string();
818        self
819    }
820
821    // from stop point id
822    pub fn from_stop_point_id(mut self, stop_point_id: &str) -> Self {
823        self.parameters.stop_point_id = stop_point_id.to_string();
824        self
825    }
826}
827
828create_endpoint!(StationTimetableWithDestinationByLine);
829
830impl RequestBuilder for StationTimetableWithDestinationByLine<'_> {
831    type Response = models::TimetableForStationWithDestinationByLineID;
832
833    fn get_request_url(&self) -> String {
834        format!(
835            "/Line/{}/Timetable/{}/to/{}",
836            self.get_parameters().line_id,
837            self.get_parameters().from_stop_point_id,
838            self.get_parameters().to_stop_point_id
839        )
840    }
841
842    fn get_parameters(&self) -> &models::Parameters {
843        &self.parameters
844    }
845
846    fn get_client(&self) -> &Client {
847        self.client
848    }
849}
850
851impl StationTimetableWithDestinationByLine<'_> {
852    // Get line id
853    pub fn line(mut self, id: linemodels::LineID) -> Self {
854        self.parameters.line_id = id.line().to_string();
855        self
856    }
857
858    // from stop point id
859    pub fn from_stop_point_id(mut self, from_stop_point_id: &str) -> Self {
860        self.parameters.from_stop_point_id = from_stop_point_id.to_string();
861        self
862    }
863
864    // to stop point id
865    pub fn to_stop_point_id(mut self, to_stop_point_id: &str) -> Self {
866        self.parameters.to_stop_point_id = to_stop_point_id.to_string();
867        self
868    }
869}
870
871create_endpoint!(SearchLineRoutesByQuery);
872
873impl RequestBuilder for SearchLineRoutesByQuery<'_> {
874    type Response = models::SearchLinesRoutesByQuery;
875
876    fn get_request_url(&self) -> String {
877        if !self.get_parameters().modes.is_empty() && self.get_parameters().service_type.is_some() {
878            format!(
879                "/Line/Search/{}?modes={}&serviceTypes={}",
880                self.get_parameters().query,
881                self.get_parameters().modes,
882                self.get_parameters().service_type.as_ref().unwrap()
883            )
884        } else if self.get_parameters().modes.is_empty()
885            && self.get_parameters().service_type.is_some()
886        {
887            format!(
888                "/Line/Search/{}?serviceTypes={}",
889                self.get_parameters().query,
890                self.get_parameters().service_type.as_ref().unwrap()
891            )
892        } else if !self.get_parameters().modes.is_empty()
893            && self.get_parameters().service_type.is_none()
894        {
895            format!(
896                "/Line/Search/{}?modes={}",
897                self.get_parameters().query,
898                self.get_parameters().modes
899            )
900        } else {
901            format!("/Line/Search/{}", self.get_parameters().query)
902        }
903    }
904
905    fn get_parameters(&self) -> &models::Parameters {
906        &self.parameters
907    }
908
909    fn get_client(&self) -> &Client {
910        self.client
911    }
912}
913
914impl SearchLineRoutesByQuery<'_> {
915    // Get line id
916    pub fn query(mut self, id: linemodels::LineID) -> Self {
917        self.parameters.query = id.line().to_string();
918        self
919    }
920
921    pub fn mode(mut self, mode: Vec<models::Mode>) -> Self {
922        let mut modes: String = "".to_owned();
923        for k in mode {
924            //k.line().to_string();
925            if modes == "" {
926                modes.push_str(k.mode().into());
927            } else {
928                modes.push_str(",");
929                modes.push_str(k.mode().into());
930            }
931        }
932        self.parameters.modes = modes;
933        self
934    }
935
936    pub fn service_type(mut self, service_types: models::ServiceTypes) -> Self {
937        self.parameters.service_type = Some(service_types.to_type().to_string());
938        self
939    }
940}