-
Notifications
You must be signed in to change notification settings - Fork 1
/
deduct_service_credit.go
73 lines (65 loc) · 2.19 KB
/
deduct_service_credit.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
package models
import (
"encoding/json"
"errors"
"strings"
)
// DeductServiceCredit represents a DeductServiceCredit struct.
type DeductServiceCredit struct {
Amount DeductServiceCreditAmount `json:"amount"`
Memo *string `json:"memo,omitempty"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for DeductServiceCredit.
// It customizes the JSON marshaling process for DeductServiceCredit objects.
func (d DeductServiceCredit) MarshalJSON() (
[]byte,
error) {
return json.Marshal(d.toMap())
}
// toMap converts the DeductServiceCredit object to a map representation for JSON marshaling.
func (d DeductServiceCredit) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, d.AdditionalProperties)
structMap["amount"] = d.Amount.toMap()
if d.Memo != nil {
structMap["memo"] = d.Memo
}
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for DeductServiceCredit.
// It customizes the JSON unmarshaling process for DeductServiceCredit objects.
func (d *DeductServiceCredit) UnmarshalJSON(input []byte) error {
var temp deductServiceCredit
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
err = temp.validate()
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "amount", "memo")
if err != nil {
return err
}
d.AdditionalProperties = additionalProperties
d.Amount = *temp.Amount
d.Memo = temp.Memo
return nil
}
// deductServiceCredit is a temporary struct used for validating the fields of DeductServiceCredit.
type deductServiceCredit struct {
Amount *DeductServiceCreditAmount `json:"amount"`
Memo *string `json:"memo,omitempty"`
}
func (d *deductServiceCredit) validate() error {
var errs []string
if d.Amount == nil {
errs = append(errs, "required field `amount` is missing for type `Deduct Service Credit`")
}
if len(errs) == 0 {
return nil
}
return errors.New(strings.Join(errs, "\n"))
}