google_cloud_optimization_v1/
builders.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    use std::sync::Arc;
20
21    /// Common implementation for [crate::client::FleetRouting] request builders.
22    #[derive(Clone, Debug)]
23    pub struct RequestBuilder<R: std::default::Default> {
24        stub: Arc<dyn crate::stubs::dynamic::FleetRouting>,
25        request: R,
26        options: gax::options::RequestOptions,
27    }
28
29    impl<R> RequestBuilder<R>
30    where
31        R: std::default::Default,
32    {
33        pub(crate) fn new(stub: Arc<dyn crate::stubs::dynamic::FleetRouting>) -> Self {
34            Self {
35                stub,
36                request: R::default(),
37                options: gax::options::RequestOptions::default(),
38            }
39        }
40    }
41
42    /// The request builder for a FleetRouting::optimize_tours call.
43    #[derive(Clone, Debug)]
44    pub struct OptimizeTours(RequestBuilder<crate::model::OptimizeToursRequest>);
45
46    impl OptimizeTours {
47        pub(crate) fn new(stub: Arc<dyn crate::stubs::dynamic::FleetRouting>) -> Self {
48            Self(RequestBuilder::new(stub))
49        }
50
51        /// Sets the full request, replacing any prior values.
52        pub fn with_request<V: Into<crate::model::OptimizeToursRequest>>(mut self, v: V) -> Self {
53            self.0.request = v.into();
54            self
55        }
56
57        /// Sets all the options, replacing any prior values.
58        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
59            self.0.options = v.into();
60            self
61        }
62
63        /// Sends the request.
64        pub async fn send(self) -> Result<crate::model::OptimizeToursResponse> {
65            (*self.0.stub)
66                .optimize_tours(self.0.request, self.0.options)
67                .await
68        }
69
70        /// Sets the value of [parent][crate::model::OptimizeToursRequest::parent].
71        pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
72            self.0.request.parent = v.into();
73            self
74        }
75
76        /// Sets the value of [timeout][crate::model::OptimizeToursRequest::timeout].
77        pub fn set_timeout<T: Into<std::option::Option<wkt::Duration>>>(mut self, v: T) -> Self {
78            self.0.request.timeout = v.into();
79            self
80        }
81
82        /// Sets the value of [model][crate::model::OptimizeToursRequest::model].
83        pub fn set_model<T: Into<std::option::Option<crate::model::ShipmentModel>>>(
84            mut self,
85            v: T,
86        ) -> Self {
87            self.0.request.model = v.into();
88            self
89        }
90
91        /// Sets the value of [solving_mode][crate::model::OptimizeToursRequest::solving_mode].
92        pub fn set_solving_mode<T: Into<crate::model::optimize_tours_request::SolvingMode>>(
93            mut self,
94            v: T,
95        ) -> Self {
96            self.0.request.solving_mode = v.into();
97            self
98        }
99
100        /// Sets the value of [search_mode][crate::model::OptimizeToursRequest::search_mode].
101        pub fn set_search_mode<T: Into<crate::model::optimize_tours_request::SearchMode>>(
102            mut self,
103            v: T,
104        ) -> Self {
105            self.0.request.search_mode = v.into();
106            self
107        }
108
109        /// Sets the value of [injected_solution_constraint][crate::model::OptimizeToursRequest::injected_solution_constraint].
110        pub fn set_injected_solution_constraint<
111            T: Into<std::option::Option<crate::model::InjectedSolutionConstraint>>,
112        >(
113            mut self,
114            v: T,
115        ) -> Self {
116            self.0.request.injected_solution_constraint = v.into();
117            self
118        }
119
120        /// Sets the value of [interpret_injected_solutions_using_labels][crate::model::OptimizeToursRequest::interpret_injected_solutions_using_labels].
121        pub fn set_interpret_injected_solutions_using_labels<T: Into<bool>>(
122            mut self,
123            v: T,
124        ) -> Self {
125            self.0.request.interpret_injected_solutions_using_labels = v.into();
126            self
127        }
128
129        /// Sets the value of [consider_road_traffic][crate::model::OptimizeToursRequest::consider_road_traffic].
130        pub fn set_consider_road_traffic<T: Into<bool>>(mut self, v: T) -> Self {
131            self.0.request.consider_road_traffic = v.into();
132            self
133        }
134
135        /// Sets the value of [populate_polylines][crate::model::OptimizeToursRequest::populate_polylines].
136        pub fn set_populate_polylines<T: Into<bool>>(mut self, v: T) -> Self {
137            self.0.request.populate_polylines = v.into();
138            self
139        }
140
141        /// Sets the value of [populate_transition_polylines][crate::model::OptimizeToursRequest::populate_transition_polylines].
142        pub fn set_populate_transition_polylines<T: Into<bool>>(mut self, v: T) -> Self {
143            self.0.request.populate_transition_polylines = v.into();
144            self
145        }
146
147        /// Sets the value of [allow_large_deadline_despite_interruption_risk][crate::model::OptimizeToursRequest::allow_large_deadline_despite_interruption_risk].
148        pub fn set_allow_large_deadline_despite_interruption_risk<T: Into<bool>>(
149            mut self,
150            v: T,
151        ) -> Self {
152            self.0
153                .request
154                .allow_large_deadline_despite_interruption_risk = v.into();
155            self
156        }
157
158        /// Sets the value of [use_geodesic_distances][crate::model::OptimizeToursRequest::use_geodesic_distances].
159        pub fn set_use_geodesic_distances<T: Into<bool>>(mut self, v: T) -> Self {
160            self.0.request.use_geodesic_distances = v.into();
161            self
162        }
163
164        /// Sets the value of [geodesic_meters_per_second][crate::model::OptimizeToursRequest::geodesic_meters_per_second].
165        pub fn set_geodesic_meters_per_second<T: Into<std::option::Option<f64>>>(
166            mut self,
167            v: T,
168        ) -> Self {
169            self.0.request.geodesic_meters_per_second = v.into();
170            self
171        }
172
173        /// Sets the value of [max_validation_errors][crate::model::OptimizeToursRequest::max_validation_errors].
174        pub fn set_max_validation_errors<T: Into<std::option::Option<i32>>>(
175            mut self,
176            v: T,
177        ) -> Self {
178            self.0.request.max_validation_errors = v.into();
179            self
180        }
181
182        /// Sets the value of [label][crate::model::OptimizeToursRequest::label].
183        pub fn set_label<T: Into<std::string::String>>(mut self, v: T) -> Self {
184            self.0.request.label = v.into();
185            self
186        }
187
188        /// Sets the value of [populate_travel_step_polylines][crate::model::OptimizeToursRequest::populate_travel_step_polylines].
189        pub fn set_populate_travel_step_polylines<T: Into<bool>>(mut self, v: T) -> Self {
190            self.0.request.populate_travel_step_polylines = v.into();
191            self
192        }
193
194        /// Sets the value of [injected_first_solution_routes][crate::model::OptimizeToursRequest::injected_first_solution_routes].
195        pub fn set_injected_first_solution_routes<T, V>(mut self, v: T) -> Self
196        where
197            T: std::iter::IntoIterator<Item = V>,
198            V: std::convert::Into<crate::model::ShipmentRoute>,
199        {
200            use std::iter::Iterator;
201            self.0.request.injected_first_solution_routes =
202                v.into_iter().map(|i| i.into()).collect();
203            self
204        }
205
206        /// Sets the value of [refresh_details_routes][crate::model::OptimizeToursRequest::refresh_details_routes].
207        pub fn set_refresh_details_routes<T, V>(mut self, v: T) -> Self
208        where
209            T: std::iter::IntoIterator<Item = V>,
210            V: std::convert::Into<crate::model::ShipmentRoute>,
211        {
212            use std::iter::Iterator;
213            self.0.request.refresh_details_routes = v.into_iter().map(|i| i.into()).collect();
214            self
215        }
216    }
217
218    impl gax::options::RequestBuilder for OptimizeTours {
219        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
220            &mut self.0.options
221        }
222    }
223
224    /// The request builder for a FleetRouting::batch_optimize_tours call.
225    #[derive(Clone, Debug)]
226    pub struct BatchOptimizeTours(RequestBuilder<crate::model::BatchOptimizeToursRequest>);
227
228    impl BatchOptimizeTours {
229        pub(crate) fn new(stub: Arc<dyn crate::stubs::dynamic::FleetRouting>) -> Self {
230            Self(RequestBuilder::new(stub))
231        }
232
233        /// Sets the full request, replacing any prior values.
234        pub fn with_request<V: Into<crate::model::BatchOptimizeToursRequest>>(
235            mut self,
236            v: V,
237        ) -> Self {
238            self.0.request = v.into();
239            self
240        }
241
242        /// Sets all the options, replacing any prior values.
243        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
244            self.0.options = v.into();
245            self
246        }
247
248        /// Sends the request.
249        ///
250        /// # Long running operations
251        ///
252        /// This starts, but does not poll, a longrunning operation. More information
253        /// on [batch_optimize_tours][crate::client::FleetRouting::batch_optimize_tours].
254        pub async fn send(self) -> Result<longrunning::model::Operation> {
255            (*self.0.stub)
256                .batch_optimize_tours(self.0.request, self.0.options)
257                .await
258        }
259
260        /// Creates a [Poller][lro::Poller] to work with `batch_optimize_tours`.
261        pub fn poller(
262            self,
263        ) -> impl lro::Poller<crate::model::BatchOptimizeToursResponse, crate::model::AsyncModelMetadata>
264        {
265            type Operation = lro::Operation<
266                crate::model::BatchOptimizeToursResponse,
267                crate::model::AsyncModelMetadata,
268            >;
269            let polling_policy = self.0.stub.get_polling_policy(&self.0.options);
270            let polling_backoff_policy = self.0.stub.get_polling_backoff_policy(&self.0.options);
271
272            let stub = self.0.stub.clone();
273            let mut options = self.0.options.clone();
274            options.set_retry_policy(gax::retry_policy::NeverRetry);
275            let query = move |name| {
276                let stub = stub.clone();
277                let options = options.clone();
278                async {
279                    let op = GetOperation::new(stub)
280                        .set_name(name)
281                        .with_options(options)
282                        .send()
283                        .await?;
284                    Ok(Operation::new(op))
285                }
286            };
287
288            let start = move || async {
289                let op = self.send().await?;
290                Ok(Operation::new(op))
291            };
292
293            lro::new_poller(polling_policy, polling_backoff_policy, start, query)
294        }
295
296        /// Sets the value of [parent][crate::model::BatchOptimizeToursRequest::parent].
297        pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
298            self.0.request.parent = v.into();
299            self
300        }
301
302        /// Sets the value of [model_configs][crate::model::BatchOptimizeToursRequest::model_configs].
303        pub fn set_model_configs<T, V>(mut self, v: T) -> Self
304        where
305            T: std::iter::IntoIterator<Item = V>,
306            V: std::convert::Into<crate::model::batch_optimize_tours_request::AsyncModelConfig>,
307        {
308            use std::iter::Iterator;
309            self.0.request.model_configs = v.into_iter().map(|i| i.into()).collect();
310            self
311        }
312    }
313
314    impl gax::options::RequestBuilder for BatchOptimizeTours {
315        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
316            &mut self.0.options
317        }
318    }
319
320    /// The request builder for a FleetRouting::get_operation call.
321    #[derive(Clone, Debug)]
322    pub struct GetOperation(RequestBuilder<longrunning::model::GetOperationRequest>);
323
324    impl GetOperation {
325        pub(crate) fn new(stub: Arc<dyn crate::stubs::dynamic::FleetRouting>) -> Self {
326            Self(RequestBuilder::new(stub))
327        }
328
329        /// Sets the full request, replacing any prior values.
330        pub fn with_request<V: Into<longrunning::model::GetOperationRequest>>(
331            mut self,
332            v: V,
333        ) -> Self {
334            self.0.request = v.into();
335            self
336        }
337
338        /// Sets all the options, replacing any prior values.
339        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
340            self.0.options = v.into();
341            self
342        }
343
344        /// Sends the request.
345        pub async fn send(self) -> Result<longrunning::model::Operation> {
346            (*self.0.stub)
347                .get_operation(self.0.request, self.0.options)
348                .await
349        }
350
351        /// Sets the value of [name][longrunning::model::GetOperationRequest::name].
352        pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
353            self.0.request.name = v.into();
354            self
355        }
356    }
357
358    impl gax::options::RequestBuilder for GetOperation {
359        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
360            &mut self.0.options
361        }
362    }
363}