1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
// this file is @generated
#![allow(clippy::doc_markdown, clippy::default_trait_access)]
#[allow(unused_imports, clippy::wildcard_imports)]
use crate::{error::Result, models::*, Configuration};
/// Query and header parameters of [`Plans::list`].
#[derive(Clone, Debug, Default)]
#[non_exhaustive]
pub struct PlansListOptions {
/// The `product_family_id` query parameter.
pub product_family_id: Option<ProductFamilyId>,
/// Search by plan name
pub search: Option<String>,
/// Filter by plan status (can be repeated)
pub status: Option<Vec<PlanStatusEnum>>,
/// Filter by plan type (can be repeated)
pub plan_type: Option<Vec<PlanTypeEnum>>,
/// Sort order. Format: `column.direction`. Allowed columns: `name`, `status`, `plan_type`, `created_at`. Direction: `asc` or `desc`. Default: `created_at.desc`.
pub order_by: Option<String>,
/// Page number (0-indexed)
pub page: Option<i32>,
/// Number of items per page
pub per_page: Option<i32>,
}
impl PlansListOptions {
/// Options with no parameter set.
#[must_use]
pub fn new() -> Self {
Self {
product_family_id: None,
search: None,
status: None,
plan_type: None,
order_by: None,
page: None,
per_page: None,
}
}
/// Sets the `product_family_id` query parameter.
#[must_use]
pub fn product_family_id(mut self, product_family_id: impl Into<ProductFamilyId>) -> Self {
self.product_family_id = Some(product_family_id.into());
self
}
/// Sets the `product_family_id` query parameter, or unsets it with `None`.
#[must_use]
pub fn maybe_product_family_id(mut self, product_family_id: Option<ProductFamilyId>) -> Self {
self.product_family_id = product_family_id;
self
}
/// Sets the `search` query parameter.
#[must_use]
pub fn search(mut self, search: impl Into<String>) -> Self {
self.search = Some(search.into());
self
}
/// Sets the `search` query parameter, or unsets it with `None`.
#[must_use]
pub fn maybe_search(mut self, search: Option<String>) -> Self {
self.search = search;
self
}
/// Sets the `status` query parameter.
#[must_use]
pub fn status(mut self, status: impl Into<Vec<PlanStatusEnum>>) -> Self {
self.status = Some(status.into());
self
}
/// Sets the `status` query parameter, or unsets it with `None`.
#[must_use]
pub fn maybe_status(mut self, status: Option<Vec<PlanStatusEnum>>) -> Self {
self.status = status;
self
}
/// Sets the `plan_type` query parameter.
#[must_use]
pub fn plan_type(mut self, plan_type: impl Into<Vec<PlanTypeEnum>>) -> Self {
self.plan_type = Some(plan_type.into());
self
}
/// Sets the `plan_type` query parameter, or unsets it with `None`.
#[must_use]
pub fn maybe_plan_type(mut self, plan_type: Option<Vec<PlanTypeEnum>>) -> Self {
self.plan_type = plan_type;
self
}
/// Sets the `order_by` query parameter.
#[must_use]
pub fn order_by(mut self, order_by: impl Into<String>) -> Self {
self.order_by = Some(order_by.into());
self
}
/// Sets the `order_by` query parameter, or unsets it with `None`.
#[must_use]
pub fn maybe_order_by(mut self, order_by: Option<String>) -> Self {
self.order_by = order_by;
self
}
/// Sets the `page` query parameter.
#[must_use]
pub fn page(mut self, page: impl Into<i32>) -> Self {
self.page = Some(page.into());
self
}
/// Sets the `page` query parameter, or unsets it with `None`.
#[must_use]
pub fn maybe_page(mut self, page: Option<i32>) -> Self {
self.page = page;
self
}
/// Sets the `per_page` query parameter.
#[must_use]
pub fn per_page(mut self, per_page: impl Into<i32>) -> Self {
self.per_page = Some(per_page.into());
self
}
/// Sets the `per_page` query parameter, or unsets it with `None`.
#[must_use]
pub fn maybe_per_page(mut self, per_page: Option<i32>) -> Self {
self.per_page = per_page;
self
}
}
/// Query and header parameters of [`Plans::retrieve`].
#[derive(Clone, Debug, Default)]
#[non_exhaustive]
pub struct PlansRetrieveOptions {
/// Filter by version: "draft", a version number, or omitted for active
pub version: Option<String>,
}
impl PlansRetrieveOptions {
/// Options with no parameter set.
#[must_use]
pub fn new() -> Self {
Self { version: None }
}
/// Sets the `version` query parameter.
#[must_use]
pub fn version(mut self, version: impl Into<String>) -> Self {
self.version = Some(version.into());
self
}
/// Sets the `version` query parameter, or unsets it with `None`.
#[must_use]
pub fn maybe_version(mut self, version: Option<String>) -> Self {
self.version = version;
self
}
}
/// The plans API, from the client's
/// [`plans`](crate::api::Meteroid::plans).
#[derive(Clone)]
pub struct Plans {
cfg: std::sync::Arc<Configuration>,
options: crate::api::RequestOptions,
}
impl std::fmt::Debug for Plans {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Plans")
.field("options", &self.options)
.finish_non_exhaustive()
}
}
impl Plans {
pub(super) fn new(cfg: std::sync::Arc<Configuration>) -> Self {
Self {
cfg,
options: crate::api::RequestOptions::default(),
}
}
/// Applies `options` (headers, timeout, retries, idempotency key) to the calls made
/// through the returned value.
#[must_use]
pub fn with_options(mut self, options: crate::api::RequestOptions) -> Self {
self.options = options;
self
}
/// The versions API, with the options of this one.
#[must_use]
pub fn versions(&self) -> super::PlansVersions {
super::PlansVersions::new(self.cfg.clone()).with_options(self.options.clone())
}
/// List plan version entitlements
///
/// `GET /api/v1/plan-versions/{plan_version_id}/entitlements`.
///
/// # Errors
///
/// An API error's body is [`RestErrorResponse`](crate::models::RestErrorResponse) (401, 404, 429).
pub fn list_plan_version_entitlements(
&self,
plan_version_id: impl Into<crate::models::PlanVersionId>,
) -> crate::api::Call<crate::models::ResolvedEntitlementListResponse> {
crate::request::Request::new(
http::Method::GET,
"/api/v1/plan-versions/{plan_version_id}/entitlements",
)
.with_path_param(
"plan_version_id",
Into::<crate::models::PlanVersionId>::into(plan_version_id),
)
.with_options(&self.options)
.json(&self.cfg)
}
/// Create plan version entitlements
///
/// Entitlements already present on this plan version are skipped.
///
/// `POST /api/v1/plan-versions/{plan_version_id}/entitlements`.
///
/// # Errors
///
/// An API error's body is [`RestErrorResponse`](crate::models::RestErrorResponse) (400, 401, 404, 429).
pub fn create_plan_version_entitlement(
&self,
plan_version_id: impl Into<crate::models::PlanVersionId>,
create_entitlements_request: crate::models::CreateEntitlementsRequest,
) -> crate::api::Call<crate::models::EntitlementListResponse> {
crate::request::Request::new(
http::Method::POST,
"/api/v1/plan-versions/{plan_version_id}/entitlements",
)
.with_path_param(
"plan_version_id",
Into::<crate::models::PlanVersionId>::into(plan_version_id),
)
.with_body_param(create_entitlements_request)
.with_options(&self.options)
.json(&self.cfg)
}
fn list_request(
&self,
options: impl Into<Option<PlansListOptions>>,
) -> crate::api::Call<crate::models::PlanListResponse> {
let PlansListOptions {
product_family_id,
search,
status,
plan_type,
order_by,
page,
per_page,
} = options.into().unwrap_or_default();
crate::request::Request::new(http::Method::GET, "/api/v1/plans")
.with_optional_query_param("product_family_id", product_family_id)
.with_optional_query_param("search", search)
.with_optional_exploded_query_param("status", status)
.with_optional_exploded_query_param("plan_type", plan_type)
.with_optional_query_param("order_by", order_by)
.with_optional_query_param("page", page)
.with_optional_query_param("per_page", per_page)
.with_options(&self.options)
.json(&self.cfg)
}
/// List plans
///
/// `GET /api/v1/plans`, a page at a time: awaiting the call gives the first
/// [`Page`](crate::api::Page), [`items`](crate::api::PageCall::items) every
/// [`Plan`](crate::models::Plan) across pages
/// and [`pages`](crate::api::PageCall::pages) every page.
///
/// # Errors
///
/// An API error's body is [`RestErrorResponse`](crate::models::RestErrorResponse) (401, 429).
pub fn list(
&self,
options: impl Into<Option<PlansListOptions>>,
) -> crate::api::PageCall<crate::models::PlanListResponse, crate::models::Plan> {
static WALK: crate::api::pagination::Walk<PlansListOptions> =
crate::api::pagination::Walk::Page {
first: 0,
get: |options| options.page.map(i64::from),
set: |options, position| options.page = i32::try_from(position).ok(),
};
let this = self.clone();
let call = move |options: PlansListOptions| this.list_request(options);
crate::api::PageCall::new(
options.into().unwrap_or_default(),
WALK,
crate::api::pages::PLANS_LIST,
call,
)
}
/// Create a plan
///
/// Create a new plan with components and pricing. Set `status` to `ACTIVE` to
/// publish immediately, or `DRAFT` to stage for review.
///
/// `POST /api/v1/plans`.
///
/// # Errors
///
/// An API error's body is [`RestErrorResponse`](crate::models::RestErrorResponse) (400, 401, 409, 429).
pub fn create(
&self,
create_plan_request: crate::models::CreatePlanRequest,
) -> crate::api::Call<crate::models::Plan> {
crate::request::Request::new(http::Method::POST, "/api/v1/plans")
.with_body_param(create_plan_request)
.with_options(&self.options)
.json(&self.cfg)
}
/// Get plan details
///
/// Retrieve a specific plan. Use `?version=draft` for the draft version,
/// `?version=2` for a specific version number, or omit for the active version.
///
/// `GET /api/v1/plans/{plan_id}`.
///
/// # Errors
///
/// An API error's body is [`RestErrorResponse`](crate::models::RestErrorResponse) (401, 404, 429).
pub fn retrieve(
&self,
plan_id: impl Into<crate::models::PlanId>,
options: impl Into<Option<PlansRetrieveOptions>>,
) -> crate::api::Call<crate::models::Plan> {
let PlansRetrieveOptions { version } = options.into().unwrap_or_default();
crate::request::Request::new(http::Method::GET, "/api/v1/plans/{plan_id}")
.with_path_param("plan_id", Into::<crate::models::PlanId>::into(plan_id))
.with_optional_query_param("version", version)
.with_options(&self.options)
.json(&self.cfg)
}
/// Replace a plan
///
/// Full replacement of a plan's version. On a draft plan, updates in-place.
/// On a published plan, creates a new version. Set `status` to `DRAFT` to
/// stage as a new draft without publishing. A usage or capacity component priced in a credit
/// unit must be sent with its `credit_unit`, or the request is refused: omitting it would bill
/// its credits as money.
///
/// `PUT /api/v1/plans/{plan_id}`.
///
/// # Errors
///
/// An API error's body is [`RestErrorResponse`](crate::models::RestErrorResponse) (400, 401, 403, 404, 429).
pub fn replace(
&self,
plan_id: impl Into<crate::models::PlanId>,
replace_plan_request: crate::models::ReplacePlanRequest,
) -> crate::api::Call<crate::models::Plan> {
crate::request::Request::new(http::Method::PUT, "/api/v1/plans/{plan_id}")
.with_path_param("plan_id", Into::<crate::models::PlanId>::into(plan_id))
.with_body_param(replace_plan_request)
.with_options(&self.options)
.json(&self.cfg)
}
/// Update plan metadata
///
/// Partially update plan-level fields (name, description, self_service_rank).
/// Does not modify version-level configuration or components.
///
/// `PATCH /api/v1/plans/{plan_id}`.
///
/// # Errors
///
/// An API error's body is [`RestErrorResponse`](crate::models::RestErrorResponse) (400, 401, 404, 429).
pub fn update(
&self,
plan_id: impl Into<crate::models::PlanId>,
patch_plan_request: crate::models::PatchPlanRequest,
) -> crate::api::Call<crate::models::Plan> {
crate::request::Request::new(http::Method::PATCH, "/api/v1/plans/{plan_id}")
.with_path_param("plan_id", Into::<crate::models::PlanId>::into(plan_id))
.with_body_param(patch_plan_request)
.with_options(&self.options)
.json(&self.cfg)
}
/// Archive a plan
///
/// `POST /api/v1/plans/{plan_id}/archive`.
///
/// # Errors
///
/// An API error's body is [`RestErrorResponse`](crate::models::RestErrorResponse) (401, 404, 429).
pub fn archive(&self, plan_id: impl Into<crate::models::PlanId>) -> crate::api::Call<()> {
crate::request::Request::new(http::Method::POST, "/api/v1/plans/{plan_id}/archive")
.with_path_param("plan_id", Into::<crate::models::PlanId>::into(plan_id))
.with_options(&self.options)
.empty(&self.cfg)
}
/// Publish a draft plan version
///
/// Publishes the current draft version, making it the active version.
///
/// `POST /api/v1/plans/{plan_id}/publish`.
///
/// # Errors
///
/// An API error's body is [`RestErrorResponse`](crate::models::RestErrorResponse) (401, 404, 409, 429).
pub fn publish(
&self,
plan_id: impl Into<crate::models::PlanId>,
) -> crate::api::Call<crate::models::Plan> {
crate::request::Request::new(http::Method::POST, "/api/v1/plans/{plan_id}/publish")
.with_path_param("plan_id", Into::<crate::models::PlanId>::into(plan_id))
.with_options(&self.options)
.json(&self.cfg)
}
/// Unarchive a plan
///
/// `POST /api/v1/plans/{plan_id}/unarchive`.
///
/// # Errors
///
/// An API error's body is [`RestErrorResponse`](crate::models::RestErrorResponse) (401, 404, 429).
pub fn unarchive(&self, plan_id: impl Into<crate::models::PlanId>) -> crate::api::Call<()> {
crate::request::Request::new(http::Method::POST, "/api/v1/plans/{plan_id}/unarchive")
.with_path_param("plan_id", Into::<crate::models::PlanId>::into(plan_id))
.with_options(&self.options)
.empty(&self.cfg)
}
}