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