-
Notifications
You must be signed in to change notification settings - Fork 1
/
breakouts.go
70 lines (63 loc) · 2.56 KB
/
breakouts.go
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
package models
import (
"encoding/json"
)
// Breakouts represents a Breakouts struct.
type Breakouts struct {
PlanAmountInCents *int64 `json:"plan_amount_in_cents,omitempty"`
PlanAmountFormatted *string `json:"plan_amount_formatted,omitempty"`
UsageAmountInCents *int64 `json:"usage_amount_in_cents,omitempty"`
UsageAmountFormatted *string `json:"usage_amount_formatted,omitempty"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for Breakouts.
// It customizes the JSON marshaling process for Breakouts objects.
func (b Breakouts) MarshalJSON() (
[]byte,
error) {
return json.Marshal(b.toMap())
}
// toMap converts the Breakouts object to a map representation for JSON marshaling.
func (b Breakouts) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, b.AdditionalProperties)
if b.PlanAmountInCents != nil {
structMap["plan_amount_in_cents"] = b.PlanAmountInCents
}
if b.PlanAmountFormatted != nil {
structMap["plan_amount_formatted"] = b.PlanAmountFormatted
}
if b.UsageAmountInCents != nil {
structMap["usage_amount_in_cents"] = b.UsageAmountInCents
}
if b.UsageAmountFormatted != nil {
structMap["usage_amount_formatted"] = b.UsageAmountFormatted
}
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for Breakouts.
// It customizes the JSON unmarshaling process for Breakouts objects.
func (b *Breakouts) UnmarshalJSON(input []byte) error {
var temp breakouts
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "plan_amount_in_cents", "plan_amount_formatted", "usage_amount_in_cents", "usage_amount_formatted")
if err != nil {
return err
}
b.AdditionalProperties = additionalProperties
b.PlanAmountInCents = temp.PlanAmountInCents
b.PlanAmountFormatted = temp.PlanAmountFormatted
b.UsageAmountInCents = temp.UsageAmountInCents
b.UsageAmountFormatted = temp.UsageAmountFormatted
return nil
}
// breakouts is a temporary struct used for validating the fields of Breakouts.
type breakouts struct {
PlanAmountInCents *int64 `json:"plan_amount_in_cents,omitempty"`
PlanAmountFormatted *string `json:"plan_amount_formatted,omitempty"`
UsageAmountInCents *int64 `json:"usage_amount_in_cents,omitempty"`
UsageAmountFormatted *string `json:"usage_amount_formatted,omitempty"`
}