lago_types/models/customer_usage.rs
1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use uuid::Uuid;
4
5/// Represents the current usage data for a customer's subscription.
6///
7/// This struct contains information about usage-based billing data
8/// within the current billing period.
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct CustomerUsage {
11 /// Start of the billing period
12 pub from_datetime: DateTime<Utc>,
13 /// End of the billing period
14 pub to_datetime: DateTime<Utc>,
15 /// Invoice issuance date
16 pub issuing_date: String,
17 /// Associated invoice identifier (if exists)
18 pub lago_invoice_id: Option<Uuid>,
19 /// Currency code (e.g., USD, EUR)
20 pub currency: String,
21 /// Total charges amount in cents (excluding taxes)
22 pub amount_cents: i64,
23 /// Tax amount in cents
24 pub taxes_amount_cents: i64,
25 /// Grand total in cents (amount + taxes)
26 pub total_amount_cents: i64,
27 /// Array of charge usage line items
28 pub charges_usage: Vec<ChargeUsage>,
29}
30
31/// Represents usage data for a specific charge.
32#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct ChargeUsage {
34 /// Aggregated unit quantity
35 pub units: String,
36 /// Total units aggregated across the period
37 pub total_aggregated_units: Option<String>,
38 /// Number of events processed
39 pub events_count: i64,
40 /// Charge amount in cents
41 pub amount_cents: i64,
42 /// Currency code
43 pub amount_currency: String,
44 /// Custom pricing unit details
45 pub pricing_unit_details: Option<PricingUnitDetails>,
46 /// Charge configuration
47 pub charge: ChargeInfo,
48 /// Billable metric details
49 pub billable_metric: BillableMetricInfo,
50 /// Applied filter breakdowns
51 pub filters: Vec<ChargeFilterUsage>,
52 /// Grouped usage data
53 pub grouped_usage: Vec<GroupedUsage>,
54}
55
56/// Pricing unit details for custom pricing
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct PricingUnitDetails {
59 /// Amount in cents
60 pub amount_cents: Option<i64>,
61 /// Short name for the pricing unit
62 pub short_name: Option<String>,
63 /// Conversion rate
64 pub conversion_rate: Option<String>,
65}
66
67/// Basic charge information within usage
68#[derive(Debug, Clone, Serialize, Deserialize)]
69pub struct ChargeInfo {
70 /// Unique identifier for the charge in Lago
71 pub lago_id: Uuid,
72 /// Charge model (standard, graduated, volume, package, percentage)
73 pub charge_model: String,
74 /// Display name for invoices
75 pub invoice_display_name: Option<String>,
76}
77
78/// Basic billable metric information within usage
79#[derive(Debug, Clone, Serialize, Deserialize)]
80pub struct BillableMetricInfo {
81 /// Unique identifier for the billable metric in Lago
82 pub lago_id: Uuid,
83 /// Name of the billable metric
84 pub name: String,
85 /// Unique code for the billable metric
86 pub code: String,
87 /// Aggregation type (count_agg, sum_agg, max_agg, etc.)
88 pub aggregation_type: String,
89}
90
91/// Filter usage breakdown
92#[derive(Debug, Clone, Serialize, Deserialize)]
93pub struct ChargeFilterUsage {
94 /// Units for this filter
95 pub units: String,
96 /// Total aggregated units for this filter
97 pub total_aggregated_units: Option<String>,
98 /// Amount in cents for this filter
99 pub amount_cents: i64,
100 /// Number of events for this filter
101 pub events_count: i64,
102 /// Display name for invoices
103 pub invoice_display_name: Option<String>,
104 /// Filter values
105 pub values: serde_json::Value,
106}
107
108/// Grouped usage data
109#[derive(Debug, Clone, Serialize, Deserialize)]
110pub struct GroupedUsage {
111 /// Units for this group
112 pub units: String,
113 /// Total aggregated units for this group
114 pub total_aggregated_units: Option<String>,
115 /// Amount in cents for this group
116 pub amount_cents: i64,
117 /// Number of events for this group
118 pub events_count: i64,
119 /// Grouped by values
120 pub grouped_by: serde_json::Value,
121 /// Filters within this group
122 pub filters: Vec<ChargeFilterUsage>,
123}