-
Notifications
You must be signed in to change notification settings - Fork 1
/
credit_account_balance_changed.go
101 lines (93 loc) · 4.24 KB
/
credit_account_balance_changed.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
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
package models
import (
"encoding/json"
"errors"
"log"
"strings"
"time"
)
// CreditAccountBalanceChanged represents a CreditAccountBalanceChanged struct.
type CreditAccountBalanceChanged struct {
Reason string `json:"reason"`
ServiceCreditAccountBalanceInCents int64 `json:"service_credit_account_balance_in_cents"`
ServiceCreditBalanceChangeInCents int64 `json:"service_credit_balance_change_in_cents"`
CurrencyCode string `json:"currency_code"`
AtTime time.Time `json:"at_time"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for CreditAccountBalanceChanged.
// It customizes the JSON marshaling process for CreditAccountBalanceChanged objects.
func (c CreditAccountBalanceChanged) MarshalJSON() (
[]byte,
error) {
return json.Marshal(c.toMap())
}
// toMap converts the CreditAccountBalanceChanged object to a map representation for JSON marshaling.
func (c CreditAccountBalanceChanged) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, c.AdditionalProperties)
structMap["reason"] = c.Reason
structMap["service_credit_account_balance_in_cents"] = c.ServiceCreditAccountBalanceInCents
structMap["service_credit_balance_change_in_cents"] = c.ServiceCreditBalanceChangeInCents
structMap["currency_code"] = c.CurrencyCode
structMap["at_time"] = c.AtTime.Format(time.RFC3339)
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for CreditAccountBalanceChanged.
// It customizes the JSON unmarshaling process for CreditAccountBalanceChanged objects.
func (c *CreditAccountBalanceChanged) UnmarshalJSON(input []byte) error {
var temp creditAccountBalanceChanged
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
err = temp.validate()
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "reason", "service_credit_account_balance_in_cents", "service_credit_balance_change_in_cents", "currency_code", "at_time")
if err != nil {
return err
}
c.AdditionalProperties = additionalProperties
c.Reason = *temp.Reason
c.ServiceCreditAccountBalanceInCents = *temp.ServiceCreditAccountBalanceInCents
c.ServiceCreditBalanceChangeInCents = *temp.ServiceCreditBalanceChangeInCents
c.CurrencyCode = *temp.CurrencyCode
AtTimeVal, err := time.Parse(time.RFC3339, *temp.AtTime)
if err != nil {
log.Fatalf("Cannot Parse at_time as % s format.", time.RFC3339)
}
c.AtTime = AtTimeVal
return nil
}
// creditAccountBalanceChanged is a temporary struct used for validating the fields of CreditAccountBalanceChanged.
type creditAccountBalanceChanged struct {
Reason *string `json:"reason"`
ServiceCreditAccountBalanceInCents *int64 `json:"service_credit_account_balance_in_cents"`
ServiceCreditBalanceChangeInCents *int64 `json:"service_credit_balance_change_in_cents"`
CurrencyCode *string `json:"currency_code"`
AtTime *string `json:"at_time"`
}
func (c *creditAccountBalanceChanged) validate() error {
var errs []string
if c.Reason == nil {
errs = append(errs, "required field `reason` is missing for type `Credit Account Balance Changed`")
}
if c.ServiceCreditAccountBalanceInCents == nil {
errs = append(errs, "required field `service_credit_account_balance_in_cents` is missing for type `Credit Account Balance Changed`")
}
if c.ServiceCreditBalanceChangeInCents == nil {
errs = append(errs, "required field `service_credit_balance_change_in_cents` is missing for type `Credit Account Balance Changed`")
}
if c.CurrencyCode == nil {
errs = append(errs, "required field `currency_code` is missing for type `Credit Account Balance Changed`")
}
if c.AtTime == nil {
errs = append(errs, "required field `at_time` is missing for type `Credit Account Balance Changed`")
}
if len(errs) == 0 {
return nil
}
return errors.New(strings.Join(errs, "\n"))
}