google_cloud_optimization_v1/
builder.rs

1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16
17pub mod fleet_routing {
18    use crate::Result;
19
20    /// A builder for [FleetRouting][crate::client::FleetRouting].
21    ///
22    /// ```
23    /// # tokio_test::block_on(async {
24    /// # use google_cloud_optimization_v1::*;
25    /// # use builder::fleet_routing::ClientBuilder;
26    /// # use client::FleetRouting;
27    /// let builder : ClientBuilder = FleetRouting::builder();
28    /// let client = builder
29    ///     .with_endpoint("https://cloudoptimization.googleapis.com")
30    ///     .build().await?;
31    /// # gax::client_builder::Result::<()>::Ok(()) });
32    /// ```
33    pub type ClientBuilder =
34        gax::client_builder::ClientBuilder<client::Factory, gaxi::options::Credentials>;
35
36    pub(crate) mod client {
37        use super::super::super::client::FleetRouting;
38        pub struct Factory;
39        impl gax::client_builder::internal::ClientFactory for Factory {
40            type Client = FleetRouting;
41            type Credentials = gaxi::options::Credentials;
42            async fn build(
43                self,
44                config: gaxi::options::ClientConfig,
45            ) -> gax::client_builder::Result<Self::Client> {
46                Self::Client::new(config).await
47            }
48        }
49    }
50
51    /// Common implementation for [crate::client::FleetRouting] request builders.
52    #[derive(Clone, Debug)]
53    pub(crate) struct RequestBuilder<R: std::default::Default> {
54        stub: std::sync::Arc<dyn super::super::stub::dynamic::FleetRouting>,
55        request: R,
56        options: gax::options::RequestOptions,
57    }
58
59    impl<R> RequestBuilder<R>
60    where
61        R: std::default::Default,
62    {
63        pub(crate) fn new(
64            stub: std::sync::Arc<dyn super::super::stub::dynamic::FleetRouting>,
65        ) -> Self {
66            Self {
67                stub,
68                request: R::default(),
69                options: gax::options::RequestOptions::default(),
70            }
71        }
72    }
73
74    /// The request builder for [FleetRouting::optimize_tours][crate::client::FleetRouting::optimize_tours] calls.
75    ///
76    /// # Example
77    /// ```no_run
78    /// # use google_cloud_optimization_v1::builder;
79    /// use builder::fleet_routing::OptimizeTours;
80    /// # tokio_test::block_on(async {
81    ///
82    /// let builder = prepare_request_builder();
83    /// let response = builder.send().await?;
84    /// # gax::Result::<()>::Ok(()) });
85    ///
86    /// fn prepare_request_builder() -> OptimizeTours {
87    ///   # panic!();
88    ///   // ... details omitted ...
89    /// }
90    /// ```
91    #[derive(Clone, Debug)]
92    pub struct OptimizeTours(RequestBuilder<crate::model::OptimizeToursRequest>);
93
94    impl OptimizeTours {
95        pub(crate) fn new(
96            stub: std::sync::Arc<dyn super::super::stub::dynamic::FleetRouting>,
97        ) -> Self {
98            Self(RequestBuilder::new(stub))
99        }
100
101        /// Sets the full request, replacing any prior values.
102        pub fn with_request<V: Into<crate::model::OptimizeToursRequest>>(mut self, v: V) -> Self {
103            self.0.request = v.into();
104            self
105        }
106
107        /// Sets all the options, replacing any prior values.
108        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
109            self.0.options = v.into();
110            self
111        }
112
113        /// Sends the request.
114        pub async fn send(self) -> Result<crate::model::OptimizeToursResponse> {
115            (*self.0.stub)
116                .optimize_tours(self.0.request, self.0.options)
117                .await
118                .map(gax::response::Response::into_body)
119        }
120
121        /// Sets the value of [parent][crate::model::OptimizeToursRequest::parent].
122        ///
123        /// This is a **required** field for requests.
124        pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
125            self.0.request.parent = v.into();
126            self
127        }
128
129        /// Sets the value of [timeout][crate::model::OptimizeToursRequest::timeout].
130        pub fn set_timeout<T>(mut self, v: T) -> Self
131        where
132            T: std::convert::Into<wkt::Duration>,
133        {
134            self.0.request.timeout = std::option::Option::Some(v.into());
135            self
136        }
137
138        /// Sets or clears the value of [timeout][crate::model::OptimizeToursRequest::timeout].
139        pub fn set_or_clear_timeout<T>(mut self, v: std::option::Option<T>) -> Self
140        where
141            T: std::convert::Into<wkt::Duration>,
142        {
143            self.0.request.timeout = v.map(|x| x.into());
144            self
145        }
146
147        /// Sets the value of [model][crate::model::OptimizeToursRequest::model].
148        pub fn set_model<T>(mut self, v: T) -> Self
149        where
150            T: std::convert::Into<crate::model::ShipmentModel>,
151        {
152            self.0.request.model = std::option::Option::Some(v.into());
153            self
154        }
155
156        /// Sets or clears the value of [model][crate::model::OptimizeToursRequest::model].
157        pub fn set_or_clear_model<T>(mut self, v: std::option::Option<T>) -> Self
158        where
159            T: std::convert::Into<crate::model::ShipmentModel>,
160        {
161            self.0.request.model = v.map(|x| x.into());
162            self
163        }
164
165        /// Sets the value of [solving_mode][crate::model::OptimizeToursRequest::solving_mode].
166        pub fn set_solving_mode<T: Into<crate::model::optimize_tours_request::SolvingMode>>(
167            mut self,
168            v: T,
169        ) -> Self {
170            self.0.request.solving_mode = v.into();
171            self
172        }
173
174        /// Sets the value of [search_mode][crate::model::OptimizeToursRequest::search_mode].
175        pub fn set_search_mode<T: Into<crate::model::optimize_tours_request::SearchMode>>(
176            mut self,
177            v: T,
178        ) -> Self {
179            self.0.request.search_mode = v.into();
180            self
181        }
182
183        /// Sets the value of [injected_first_solution_routes][crate::model::OptimizeToursRequest::injected_first_solution_routes].
184        pub fn set_injected_first_solution_routes<T, V>(mut self, v: T) -> Self
185        where
186            T: std::iter::IntoIterator<Item = V>,
187            V: std::convert::Into<crate::model::ShipmentRoute>,
188        {
189            use std::iter::Iterator;
190            self.0.request.injected_first_solution_routes =
191                v.into_iter().map(|i| i.into()).collect();
192            self
193        }
194
195        /// Sets the value of [injected_solution_constraint][crate::model::OptimizeToursRequest::injected_solution_constraint].
196        pub fn set_injected_solution_constraint<T>(mut self, v: T) -> Self
197        where
198            T: std::convert::Into<crate::model::InjectedSolutionConstraint>,
199        {
200            self.0.request.injected_solution_constraint = std::option::Option::Some(v.into());
201            self
202        }
203
204        /// Sets or clears the value of [injected_solution_constraint][crate::model::OptimizeToursRequest::injected_solution_constraint].
205        pub fn set_or_clear_injected_solution_constraint<T>(
206            mut self,
207            v: std::option::Option<T>,
208        ) -> Self
209        where
210            T: std::convert::Into<crate::model::InjectedSolutionConstraint>,
211        {
212            self.0.request.injected_solution_constraint = v.map(|x| x.into());
213            self
214        }
215
216        /// Sets the value of [refresh_details_routes][crate::model::OptimizeToursRequest::refresh_details_routes].
217        pub fn set_refresh_details_routes<T, V>(mut self, v: T) -> Self
218        where
219            T: std::iter::IntoIterator<Item = V>,
220            V: std::convert::Into<crate::model::ShipmentRoute>,
221        {
222            use std::iter::Iterator;
223            self.0.request.refresh_details_routes = v.into_iter().map(|i| i.into()).collect();
224            self
225        }
226
227        /// Sets the value of [interpret_injected_solutions_using_labels][crate::model::OptimizeToursRequest::interpret_injected_solutions_using_labels].
228        pub fn set_interpret_injected_solutions_using_labels<T: Into<bool>>(
229            mut self,
230            v: T,
231        ) -> Self {
232            self.0.request.interpret_injected_solutions_using_labels = v.into();
233            self
234        }
235
236        /// Sets the value of [consider_road_traffic][crate::model::OptimizeToursRequest::consider_road_traffic].
237        pub fn set_consider_road_traffic<T: Into<bool>>(mut self, v: T) -> Self {
238            self.0.request.consider_road_traffic = v.into();
239            self
240        }
241
242        /// Sets the value of [populate_polylines][crate::model::OptimizeToursRequest::populate_polylines].
243        pub fn set_populate_polylines<T: Into<bool>>(mut self, v: T) -> Self {
244            self.0.request.populate_polylines = v.into();
245            self
246        }
247
248        /// Sets the value of [populate_transition_polylines][crate::model::OptimizeToursRequest::populate_transition_polylines].
249        pub fn set_populate_transition_polylines<T: Into<bool>>(mut self, v: T) -> Self {
250            self.0.request.populate_transition_polylines = v.into();
251            self
252        }
253
254        /// Sets the value of [allow_large_deadline_despite_interruption_risk][crate::model::OptimizeToursRequest::allow_large_deadline_despite_interruption_risk].
255        pub fn set_allow_large_deadline_despite_interruption_risk<T: Into<bool>>(
256            mut self,
257            v: T,
258        ) -> Self {
259            self.0
260                .request
261                .allow_large_deadline_despite_interruption_risk = v.into();
262            self
263        }
264
265        /// Sets the value of [use_geodesic_distances][crate::model::OptimizeToursRequest::use_geodesic_distances].
266        pub fn set_use_geodesic_distances<T: Into<bool>>(mut self, v: T) -> Self {
267            self.0.request.use_geodesic_distances = v.into();
268            self
269        }
270
271        /// Sets the value of [geodesic_meters_per_second][crate::model::OptimizeToursRequest::geodesic_meters_per_second].
272        pub fn set_geodesic_meters_per_second<T>(mut self, v: T) -> Self
273        where
274            T: std::convert::Into<f64>,
275        {
276            self.0.request.geodesic_meters_per_second = std::option::Option::Some(v.into());
277            self
278        }
279
280        /// Sets or clears the value of [geodesic_meters_per_second][crate::model::OptimizeToursRequest::geodesic_meters_per_second].
281        pub fn set_or_clear_geodesic_meters_per_second<T>(
282            mut self,
283            v: std::option::Option<T>,
284        ) -> Self
285        where
286            T: std::convert::Into<f64>,
287        {
288            self.0.request.geodesic_meters_per_second = v.map(|x| x.into());
289            self
290        }
291
292        /// Sets the value of [max_validation_errors][crate::model::OptimizeToursRequest::max_validation_errors].
293        pub fn set_max_validation_errors<T>(mut self, v: T) -> Self
294        where
295            T: std::convert::Into<i32>,
296        {
297            self.0.request.max_validation_errors = std::option::Option::Some(v.into());
298            self
299        }
300
301        /// Sets or clears the value of [max_validation_errors][crate::model::OptimizeToursRequest::max_validation_errors].
302        pub fn set_or_clear_max_validation_errors<T>(mut self, v: std::option::Option<T>) -> Self
303        where
304            T: std::convert::Into<i32>,
305        {
306            self.0.request.max_validation_errors = v.map(|x| x.into());
307            self
308        }
309
310        /// Sets the value of [label][crate::model::OptimizeToursRequest::label].
311        pub fn set_label<T: Into<std::string::String>>(mut self, v: T) -> Self {
312            self.0.request.label = v.into();
313            self
314        }
315
316        /// Sets the value of [populate_travel_step_polylines][crate::model::OptimizeToursRequest::populate_travel_step_polylines].
317        #[deprecated]
318        pub fn set_populate_travel_step_polylines<T: Into<bool>>(mut self, v: T) -> Self {
319            self.0.request.populate_travel_step_polylines = v.into();
320            self
321        }
322    }
323
324    #[doc(hidden)]
325    impl gax::options::internal::RequestBuilder for OptimizeTours {
326        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
327            &mut self.0.options
328        }
329    }
330
331    /// The request builder for [FleetRouting::batch_optimize_tours][crate::client::FleetRouting::batch_optimize_tours] calls.
332    ///
333    /// # Example
334    /// ```no_run
335    /// # use google_cloud_optimization_v1::builder;
336    /// use builder::fleet_routing::BatchOptimizeTours;
337    /// # tokio_test::block_on(async {
338    /// use lro::Poller;
339    ///
340    /// let builder = prepare_request_builder();
341    /// let response = builder.poller().until_done().await?;
342    /// # gax::Result::<()>::Ok(()) });
343    ///
344    /// fn prepare_request_builder() -> BatchOptimizeTours {
345    ///   # panic!();
346    ///   // ... details omitted ...
347    /// }
348    /// ```
349    #[derive(Clone, Debug)]
350    pub struct BatchOptimizeTours(RequestBuilder<crate::model::BatchOptimizeToursRequest>);
351
352    impl BatchOptimizeTours {
353        pub(crate) fn new(
354            stub: std::sync::Arc<dyn super::super::stub::dynamic::FleetRouting>,
355        ) -> Self {
356            Self(RequestBuilder::new(stub))
357        }
358
359        /// Sets the full request, replacing any prior values.
360        pub fn with_request<V: Into<crate::model::BatchOptimizeToursRequest>>(
361            mut self,
362            v: V,
363        ) -> Self {
364            self.0.request = v.into();
365            self
366        }
367
368        /// Sets all the options, replacing any prior values.
369        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
370            self.0.options = v.into();
371            self
372        }
373
374        /// Sends the request.
375        ///
376        /// # Long running operations
377        ///
378        /// This starts, but does not poll, a longrunning operation. More information
379        /// on [batch_optimize_tours][crate::client::FleetRouting::batch_optimize_tours].
380        pub async fn send(self) -> Result<longrunning::model::Operation> {
381            (*self.0.stub)
382                .batch_optimize_tours(self.0.request, self.0.options)
383                .await
384                .map(gax::response::Response::into_body)
385        }
386
387        /// Creates a [Poller][lro::Poller] to work with `batch_optimize_tours`.
388        pub fn poller(
389            self,
390        ) -> impl lro::Poller<crate::model::BatchOptimizeToursResponse, crate::model::AsyncModelMetadata>
391        {
392            type Operation = lro::internal::Operation<
393                crate::model::BatchOptimizeToursResponse,
394                crate::model::AsyncModelMetadata,
395            >;
396            let polling_error_policy = self.0.stub.get_polling_error_policy(&self.0.options);
397            let polling_backoff_policy = self.0.stub.get_polling_backoff_policy(&self.0.options);
398
399            let stub = self.0.stub.clone();
400            let mut options = self.0.options.clone();
401            options.set_retry_policy(gax::retry_policy::NeverRetry);
402            let query = move |name| {
403                let stub = stub.clone();
404                let options = options.clone();
405                async {
406                    let op = GetOperation::new(stub)
407                        .set_name(name)
408                        .with_options(options)
409                        .send()
410                        .await?;
411                    Ok(Operation::new(op))
412                }
413            };
414
415            let start = move || async {
416                let op = self.send().await?;
417                Ok(Operation::new(op))
418            };
419
420            lro::internal::new_poller(polling_error_policy, polling_backoff_policy, start, query)
421        }
422
423        /// Sets the value of [parent][crate::model::BatchOptimizeToursRequest::parent].
424        ///
425        /// This is a **required** field for requests.
426        pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
427            self.0.request.parent = v.into();
428            self
429        }
430
431        /// Sets the value of [model_configs][crate::model::BatchOptimizeToursRequest::model_configs].
432        ///
433        /// This is a **required** field for requests.
434        pub fn set_model_configs<T, V>(mut self, v: T) -> Self
435        where
436            T: std::iter::IntoIterator<Item = V>,
437            V: std::convert::Into<crate::model::batch_optimize_tours_request::AsyncModelConfig>,
438        {
439            use std::iter::Iterator;
440            self.0.request.model_configs = v.into_iter().map(|i| i.into()).collect();
441            self
442        }
443    }
444
445    #[doc(hidden)]
446    impl gax::options::internal::RequestBuilder for BatchOptimizeTours {
447        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
448            &mut self.0.options
449        }
450    }
451
452    /// The request builder for [FleetRouting::get_operation][crate::client::FleetRouting::get_operation] calls.
453    ///
454    /// # Example
455    /// ```no_run
456    /// # use google_cloud_optimization_v1::builder;
457    /// use builder::fleet_routing::GetOperation;
458    /// # tokio_test::block_on(async {
459    ///
460    /// let builder = prepare_request_builder();
461    /// let response = builder.send().await?;
462    /// # gax::Result::<()>::Ok(()) });
463    ///
464    /// fn prepare_request_builder() -> GetOperation {
465    ///   # panic!();
466    ///   // ... details omitted ...
467    /// }
468    /// ```
469    #[derive(Clone, Debug)]
470    pub struct GetOperation(RequestBuilder<longrunning::model::GetOperationRequest>);
471
472    impl GetOperation {
473        pub(crate) fn new(
474            stub: std::sync::Arc<dyn super::super::stub::dynamic::FleetRouting>,
475        ) -> Self {
476            Self(RequestBuilder::new(stub))
477        }
478
479        /// Sets the full request, replacing any prior values.
480        pub fn with_request<V: Into<longrunning::model::GetOperationRequest>>(
481            mut self,
482            v: V,
483        ) -> Self {
484            self.0.request = v.into();
485            self
486        }
487
488        /// Sets all the options, replacing any prior values.
489        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
490            self.0.options = v.into();
491            self
492        }
493
494        /// Sends the request.
495        pub async fn send(self) -> Result<longrunning::model::Operation> {
496            (*self.0.stub)
497                .get_operation(self.0.request, self.0.options)
498                .await
499                .map(gax::response::Response::into_body)
500        }
501
502        /// Sets the value of [name][longrunning::model::GetOperationRequest::name].
503        pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
504            self.0.request.name = v.into();
505            self
506        }
507    }
508
509    #[doc(hidden)]
510    impl gax::options::internal::RequestBuilder for GetOperation {
511        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
512            &mut self.0.options
513        }
514    }
515}