Skip to main content

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