Repository navigation
Expand file tree
/
Copy pathUsageResponse.java
More file actions
360 lines (322 loc) · 10.9 KB
/
Copy pathUsageResponse.java
File metadata and controls
360 lines (322 loc) · 10.9 KB
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
// This file is @generated
package com.meteroid.models;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import com.meteroid.internal.JsonField;
import com.meteroid.internal.Utils;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
/** Immutable: build one with {@link #builder()}, change a copy with {@link #toBuilder()}. */
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonAutoDetect(
getterVisibility = Visibility.NONE,
isGetterVisibility = Visibility.NONE,
setterVisibility = Visibility.NONE)
public final class UsageResponse {
@JsonProperty("computed_at")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private JsonField<OffsetDateTime> computedAt = JsonField.missing();
@JsonProperty("period_end")
private LocalDate periodEnd;
@JsonProperty("period_start")
private LocalDate periodStart;
@JsonProperty("totals")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private JsonField<List<UsageCost>> totals = JsonField.missing();
@JsonProperty("usage")
private List<MetricUsage> usage;
private final Map<String, JsonNode> additionalProperties = new LinkedHashMap<>();
private UsageResponse() {}
private UsageResponse(Builder builder) {
this.computedAt = builder.computedAt;
this.periodEnd = builder.periodEnd;
this.periodStart = builder.periodStart;
this.totals = builder.totals.map(Utils::copyList);
this.usage = Utils.copyList(builder.usage);
this.additionalProperties.putAll(builder.additionalProperties);
}
/**
* A builder of {@code UsageResponse}.
*
* @return a new builder
*/
public static Builder builder() {
return new Builder();
}
/**
* A builder starting from this value.
*
* @return a new builder
*/
public Builder toBuilder() {
Builder builder = new Builder();
builder.computedAt = computedAt;
builder.periodEnd = periodEnd;
builder.periodStart = periodStart;
builder.totals = totals.map(Utils::mutableList);
builder.usage = Utils.mutableList(usage);
builder.additionalProperties.putAll(additionalProperties);
return builder;
}
/**
* Beta: when <code>totals</code> and the metrics' <code>costs</code> were computed. These are
* present only when a subscription's current billing period is read (no <code>start_date</code>
* nor <code>end_date</code>) and its usage could be priced.
*
* @return the value, empty when unset or null
*/
public Optional<OffsetDateTime> computedAt() {
return computedAt.asOptional();
}
/**
* The {@code period_end} property.
*
* @return the value, never null
*/
public LocalDate periodEnd() {
return Utils.required(periodEnd, "period_end");
}
/**
* The {@code period_start} property.
*
* @return the value, never null
*/
public LocalDate periodStart() {
return Utils.required(periodStart, "period_start");
}
/**
* Beta: the sum of the metrics' <code>costs</code>, per currency or credit unit.
*
* @return the value, empty when unset or null
*/
public Optional<List<UsageCost>> totals() {
return totals.asOptional();
}
/**
* The {@code usage} property.
*
* @return the value, never null
*/
public List<MetricUsage> usage() {
return Utils.required(usage, "usage");
}
/**
* Properties this version of the SDK does not know, kept as received and sent back.
*
* @return the properties by name, unmodifiable
*/
public Map<String, JsonNode> additionalProperties() {
return Collections.unmodifiableMap(additionalProperties);
}
@JsonAnyGetter
private Map<String, JsonNode> anyProperties() {
return additionalProperties;
}
@JsonAnySetter
private void putAnyProperty(String name, JsonNode value) {
additionalProperties.put(name, value);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
UsageResponse that = (UsageResponse) o;
return Objects.equals(computedAt, that.computedAt)
&& Objects.equals(periodEnd, that.periodEnd)
&& Objects.equals(periodStart, that.periodStart)
&& Objects.equals(totals, that.totals)
&& Objects.equals(usage, that.usage)
&& Objects.equals(additionalProperties, that.additionalProperties);
}
@Override
public int hashCode() {
return Objects.hash(
computedAt, periodEnd, periodStart, totals, usage, additionalProperties);
}
@Override
public String toString() {
return "UsageResponse{"
+ "computedAt="
+ computedAt
+ ", periodEnd="
+ periodEnd
+ ", periodStart="
+ periodStart
+ ", totals="
+ totals
+ ", usage="
+ usage
+ ", additionalProperties="
+ additionalProperties
+ "}";
}
/** Builds {@link UsageResponse}. */
public static final class Builder {
private JsonField<OffsetDateTime> computedAt = JsonField.missing();
private LocalDate periodEnd;
private LocalDate periodStart;
private JsonField<List<UsageCost>> totals = JsonField.missing();
private List<MetricUsage> usage;
private final Map<String, JsonNode> additionalProperties = new LinkedHashMap<>();
private Builder() {}
/**
* Beta: when <code>totals</code> and the metrics' <code>costs</code> were computed. These
* are present only when a subscription's current billing period is read (no <code>
* start_date</code> nor <code>end_date</code>) and its usage could be priced.
*
* @param computedAt the value, null to send an explicit {@code null}
* @return this builder
*/
public Builder computedAt(OffsetDateTime computedAt) {
this.computedAt = JsonField.ofNullable(computedAt);
return this;
}
/**
* The {@code period_end} property.
*
* @param periodEnd the value
* @return this builder
*/
public Builder periodEnd(LocalDate periodEnd) {
this.periodEnd = periodEnd;
return this;
}
/**
* The {@code period_start} property.
*
* @param periodStart the value
* @return this builder
*/
public Builder periodStart(LocalDate periodStart) {
this.periodStart = periodStart;
return this;
}
/**
* Beta: the sum of the metrics' <code>costs</code>, per currency or credit unit.
*
* @param totals the value, null to send an explicit {@code null}
* @return this builder
*/
public Builder totals(List<UsageCost> totals) {
this.totals = JsonField.ofNullable(Utils.mutableList(totals));
return this;
}
/**
* Adds an item to {@code totals}.
*
* @param item the item
* @return this builder
*/
public Builder addTotalsItem(UsageCost item) {
List<UsageCost> items = this.totals.orNull();
if (items == null) {
items = new ArrayList<>();
this.totals = JsonField.ofNullable(items);
}
items.add(item);
return this;
}
/**
* The {@code usage} property.
*
* @param usage the value
* @return this builder
*/
public Builder usage(List<MetricUsage> usage) {
this.usage = Utils.mutableList(usage);
return this;
}
/**
* Adds an item to {@code usage}.
*
* @param item the item
* @return this builder
*/
public Builder addUsageItem(MetricUsage item) {
if (this.usage == null) {
this.usage = new ArrayList<>();
}
this.usage.add(item);
return this;
}
/**
* A property the SDK does not know, sent along.
*
* @param name the property name
* @param value the JSON value
* @return this builder
*/
public Builder putAdditionalProperty(String name, JsonNode value) {
additionalProperties.put(name, value);
return this;
}
/**
* Properties the SDK does not know, sent along.
*
* @param additionalProperties the properties by name
* @return this builder
*/
public Builder putAllAdditionalProperties(Map<String, JsonNode> additionalProperties) {
this.additionalProperties.putAll(additionalProperties);
return this;
}
/**
* Leaves out a property the SDK does not know.
*
* @param name the property name
* @return this builder
*/
public Builder removeAdditionalProperty(String name) {
additionalProperties.remove(name);
return this;
}
/**
* The {@code UsageResponse}.
*
* @return the immutable value
* @throws IllegalStateException when a required property is not set
*/
public UsageResponse build() {
Utils.checkRequired(periodEnd, "period_end");
Utils.checkRequired(periodStart, "period_start");
Utils.checkRequired(usage, "usage");
return new UsageResponse(this);
}
}
/**
* Parse {@code json} as {@code UsageResponse}.
*
* @param json the JSON text
* @return the value
* @throws com.meteroid.exceptions.InvalidDataException if it is not valid JSON of this shape
*/
public static UsageResponse fromJson(String json) {
return Utils.parse(json, UsageResponse.class);
}
/**
* This value as JSON.
*
* @return the JSON text
*/
public String toJson() {
return Utils.json(this);
}
}