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