lago-types 0.1.25

Types definitions for Lago API
Documentation
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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
use serde::{Deserialize, Serialize};

use crate::filters::common::ListFilters;
use crate::filters::subscription::SubscriptionFilters;
use crate::models::{PaginationParams, SubscriptionActivationRuleType, SubscriptionBillingTime};

/// Request parameters for listing subscriptions.
#[derive(Debug, Clone)]
pub struct ListSubscriptionsRequest {
    pub pagination: PaginationParams,
    pub filters: SubscriptionFilters,
}

impl ListSubscriptionsRequest {
    /// Creates a new empty list subscriptions request.
    pub fn new() -> Self {
        Self {
            pagination: PaginationParams::default(),
            filters: SubscriptionFilters::default(),
        }
    }

    /// Sets the pagination parameters for the request.
    pub fn with_pagination(mut self, pagination: PaginationParams) -> Self {
        self.pagination = pagination;
        self
    }

    /// Sets the subscription filters for the request.
    pub fn with_filters(mut self, filters: SubscriptionFilters) -> Self {
        self.filters = filters;
        self
    }

    /// Converts the request parameters into HTTP query parameters.
    pub fn to_query_params(&self) -> Vec<(&str, String)> {
        let mut params = self.pagination.to_query_params();
        params.extend(self.filters.to_query_params());
        params
    }
}

impl Default for ListSubscriptionsRequest {
    fn default() -> Self {
        Self::new()
    }
}

/// Request parameters for retrieving a specific subscription.
#[derive(Debug, Clone)]
pub struct GetSubscriptionRequest {
    /// The external unique identifier of the subscription.
    pub external_id: String,
}

impl GetSubscriptionRequest {
    /// Creates a new get subscription request.
    pub fn new(external_id: String) -> Self {
        Self { external_id }
    }
}

/// Request parameters for listing a customer's subscriptions.
#[derive(Debug, Clone)]
pub struct ListCustomerSubscriptionsRequest {
    /// The external unique identifier of the customer.
    pub external_customer_id: String,
    pub pagination: PaginationParams,
    pub filters: SubscriptionFilters,
}

impl ListCustomerSubscriptionsRequest {
    /// Creates a new list customer subscriptions request.
    pub fn new(external_customer_id: String) -> Self {
        Self {
            external_customer_id,
            pagination: PaginationParams::default(),
            filters: SubscriptionFilters::default(),
        }
    }

    /// Sets the pagination parameters for the request.
    pub fn with_pagination(mut self, pagination: PaginationParams) -> Self {
        self.pagination = pagination;
        self
    }

    /// Sets the subscription filters for the request.
    pub fn with_filters(mut self, filters: SubscriptionFilters) -> Self {
        self.filters = filters;
        self
    }

    /// Converts the request parameters into HTTP query parameters.
    pub fn to_query_params(&self) -> Vec<(&str, String)> {
        let mut params = self.pagination.to_query_params();
        params.extend(self.filters.to_query_params());
        params
    }
}

/// Input data for creating a subscription.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateSubscriptionInput {
    /// External unique identifier for the customer.
    pub external_customer_id: String,
    /// Code of the plan to assign to the subscription.
    pub plan_code: String,
    /// Optional display name for the subscription.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Optional external unique identifier for the subscription.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub external_id: Option<String>,
    /// Billing time determines when recurring billing cycles occur.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub billing_time: Option<SubscriptionBillingTime>,
    /// The subscription start date (ISO 8601 format).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub subscription_at: Option<String>,
    /// The subscription end date (ISO 8601 format).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ending_at: Option<String>,
    /// Plan overrides to customize the plan for this subscription.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub plan_overrides: Option<SubscriptionPlanOverrides>,
    /// Activation rules that gate the subscription activation.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub activation_rules: Option<Vec<SubscriptionActivationRuleInput>>,
    /// Purchase order number added to invoices generated for this subscription.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub purchase_order_number: Option<String>,
}

impl CreateSubscriptionInput {
    /// Creates a new subscription input with required fields.
    pub fn new(external_customer_id: String, plan_code: String) -> Self {
        Self {
            external_customer_id,
            plan_code,
            name: None,
            external_id: None,
            billing_time: None,
            subscription_at: None,
            ending_at: None,
            plan_overrides: None,
            activation_rules: None,
            purchase_order_number: None,
        }
    }

    /// Sets the subscription name.
    pub fn with_name(mut self, name: String) -> Self {
        self.name = Some(name);
        self
    }

    /// Sets the external ID.
    pub fn with_external_id(mut self, external_id: String) -> Self {
        self.external_id = Some(external_id);
        self
    }

    /// Sets the billing time.
    pub fn with_billing_time(mut self, billing_time: SubscriptionBillingTime) -> Self {
        self.billing_time = Some(billing_time);
        self
    }

    /// Sets the subscription start date.
    pub fn with_subscription_at(mut self, subscription_at: String) -> Self {
        self.subscription_at = Some(subscription_at);
        self
    }

    /// Sets the subscription end date.
    pub fn with_ending_at(mut self, ending_at: String) -> Self {
        self.ending_at = Some(ending_at);
        self
    }

    /// Sets plan overrides.
    pub fn with_plan_overrides(mut self, plan_overrides: SubscriptionPlanOverrides) -> Self {
        self.plan_overrides = Some(plan_overrides);
        self
    }

    /// Sets the activation rules.
    pub fn with_activation_rules(
        mut self,
        activation_rules: Vec<SubscriptionActivationRuleInput>,
    ) -> Self {
        self.activation_rules = Some(activation_rules);
        self
    }

    /// Sets the purchase order number.
    pub fn with_purchase_order_number(mut self, purchase_order_number: String) -> Self {
        self.purchase_order_number = Some(purchase_order_number);
        self
    }
}

/// Request for creating a subscription.
#[derive(Debug, Clone, Serialize)]
pub struct CreateSubscriptionRequest {
    pub subscription: CreateSubscriptionInput,
}

impl CreateSubscriptionRequest {
    /// Creates a new create subscription request.
    pub fn new(input: CreateSubscriptionInput) -> Self {
        Self {
            subscription: input,
        }
    }
}

/// Input data for updating a subscription.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateSubscriptionInput {
    /// Optional new name for the subscription.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Optional new end date for the subscription.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ending_at: Option<String>,
    /// Optional new plan code (for plan changes).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub plan_code: Option<String>,
    /// Optional new subscription date.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub subscription_at: Option<String>,
    /// Plan overrides to customize the plan for this subscription.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub plan_overrides: Option<SubscriptionPlanOverrides>,
    /// Activation rules that gate the subscription activation.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub activation_rules: Option<Vec<SubscriptionActivationRuleInput>>,
    /// Purchase order number added to invoices generated for this subscription.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub purchase_order_number: Option<String>,
}

impl UpdateSubscriptionInput {
    /// Creates a new empty update subscription input.
    pub fn new() -> Self {
        Self {
            name: None,
            ending_at: None,
            plan_code: None,
            subscription_at: None,
            plan_overrides: None,
            activation_rules: None,
            purchase_order_number: None,
        }
    }

    /// Sets the subscription name.
    pub fn with_name(mut self, name: String) -> Self {
        self.name = Some(name);
        self
    }

    /// Sets the subscription end date.
    pub fn with_ending_at(mut self, ending_at: String) -> Self {
        self.ending_at = Some(ending_at);
        self
    }

    /// Sets the plan code (for plan changes).
    pub fn with_plan_code(mut self, plan_code: String) -> Self {
        self.plan_code = Some(plan_code);
        self
    }

    /// Sets the subscription date.
    pub fn with_subscription_at(mut self, subscription_at: String) -> Self {
        self.subscription_at = Some(subscription_at);
        self
    }

    /// Sets plan overrides.
    pub fn with_plan_overrides(mut self, plan_overrides: SubscriptionPlanOverrides) -> Self {
        self.plan_overrides = Some(plan_overrides);
        self
    }

    /// Sets the activation rules.
    pub fn with_activation_rules(
        mut self,
        activation_rules: Vec<SubscriptionActivationRuleInput>,
    ) -> Self {
        self.activation_rules = Some(activation_rules);
        self
    }

    /// Sets the purchase order number.
    pub fn with_purchase_order_number(mut self, purchase_order_number: String) -> Self {
        self.purchase_order_number = Some(purchase_order_number);
        self
    }
}

impl Default for UpdateSubscriptionInput {
    fn default() -> Self {
        Self::new()
    }
}

/// Request for updating a subscription.
#[derive(Debug, Clone, Serialize)]
pub struct UpdateSubscriptionRequest {
    /// The external unique identifier of the subscription to update.
    #[serde(skip)]
    pub external_id: String,
    /// The subscription update data.
    pub subscription: UpdateSubscriptionInput,
}

impl UpdateSubscriptionRequest {
    /// Creates a new update subscription request.
    pub fn new(external_id: String, input: UpdateSubscriptionInput) -> Self {
        Self {
            external_id,
            subscription: input,
        }
    }
}

/// Request for deleting a subscription.
#[derive(Debug, Clone)]
pub struct DeleteSubscriptionRequest {
    /// The external unique identifier of the subscription to delete.
    pub external_id: String,
    /// Optional status to set the subscription to (defaults to terminated).
    pub status: Option<String>,
}

impl DeleteSubscriptionRequest {
    /// Creates a new delete subscription request.
    pub fn new(external_id: String) -> Self {
        Self {
            external_id,
            status: None,
        }
    }

    /// Sets the target status for the subscription.
    pub fn with_status(mut self, status: String) -> Self {
        self.status = Some(status);
        self
    }

    /// Converts the request parameters into HTTP query parameters.
    pub fn to_query_params(&self) -> Vec<(&str, String)> {
        let mut params = Vec::new();
        if let Some(status) = &self.status {
            params.push(("status", status.clone()));
        }
        params
    }
}

/// Plan overrides to customize a plan for a specific subscription.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct SubscriptionPlanOverrides {
    /// Override the base amount in cents.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub amount_cents: Option<i64>,
    /// Override the currency.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub amount_currency: Option<String>,
    /// Override the plan description.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    /// Override the invoice display name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub invoice_display_name: Option<String>,
    /// Override the plan name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Override the tax codes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tax_codes: Option<Vec<String>>,
    /// Override the trial period in days.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub trial_period: Option<f64>,
    /// Override the minimum commitment.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub minimum_commitment: Option<SubscriptionMinimumCommitmentOverride>,
    /// Override specific charges.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub charges: Option<Vec<SubscriptionChargeOverride>>,
}

impl SubscriptionPlanOverrides {
    /// Creates a new empty plan overrides object.
    pub fn new() -> Self {
        Self::default()
    }

    /// Sets the amount in cents override.
    pub fn with_amount_cents(mut self, amount_cents: i64) -> Self {
        self.amount_cents = Some(amount_cents);
        self
    }

    /// Sets the currency override.
    pub fn with_amount_currency(mut self, currency: String) -> Self {
        self.amount_currency = Some(currency);
        self
    }

    /// Sets the description override.
    pub fn with_description(mut self, description: String) -> Self {
        self.description = Some(description);
        self
    }

    /// Sets the invoice display name override.
    pub fn with_invoice_display_name(mut self, name: String) -> Self {
        self.invoice_display_name = Some(name);
        self
    }

    /// Sets the name override.
    pub fn with_name(mut self, name: String) -> Self {
        self.name = Some(name);
        self
    }

    /// Sets the trial period override.
    pub fn with_trial_period(mut self, days: f64) -> Self {
        self.trial_period = Some(days);
        self
    }
}

/// Minimum commitment override for a subscription.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SubscriptionMinimumCommitmentOverride {
    /// Minimum commitment amount in cents.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub amount_cents: Option<i64>,
    /// Invoice display name for the minimum commitment.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub invoice_display_name: Option<String>,
    /// Tax codes for the minimum commitment.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tax_codes: Option<Vec<String>>,
}

/// Charge override for a subscription.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SubscriptionChargeOverride {
    /// The ID of the charge to override.
    pub id: String,
    /// Override the billable metric ID.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub billable_metric_id: Option<String>,
    /// Override the invoice display name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub invoice_display_name: Option<String>,
    /// Override the minimum amount in cents.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_amount_cents: Option<i64>,
    /// Override tax codes for this charge.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tax_codes: Option<Vec<String>>,
    /// Override the pricing properties.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub properties: Option<serde_json::Value>,
}

/// Input for an activation rule that gates a subscription's activation.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SubscriptionActivationRuleInput {
    /// The type of the activation rule.
    #[serde(rename = "type")]
    pub rule_type: SubscriptionActivationRuleType,
    /// Hours the subscription stays incomplete awaiting payment before cancellation.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub timeout_hours: Option<i64>,
}

impl SubscriptionActivationRuleInput {
    /// Creates a new activation rule input of the given type.
    pub fn new(rule_type: SubscriptionActivationRuleType) -> Self {
        Self {
            rule_type,
            timeout_hours: None,
        }
    }

    /// Sets the timeout in hours.
    pub fn with_timeout_hours(mut self, timeout_hours: i64) -> Self {
        self.timeout_hours = Some(timeout_hours);
        self
    }
}