forked from pagarme/pagarme-golang-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getSubscriptionItemResponse.go
148 lines (141 loc) · 5.02 KB
/
getSubscriptionItemResponse.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
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
package models
import (
"encoding/json"
"log"
"time"
"github.com/apimatic/go-core-runtime/types"
)
type GetSubscriptionItemResponse struct {
Id types.Optional[string] `json:"id"`
Description types.Optional[string] `json:"description"`
Status types.Optional[string] `json:"status"`
CreatedAt types.Optional[time.Time] `json:"created_at"`
UpdatedAt types.Optional[time.Time] `json:"updated_at"`
PricingScheme types.Optional[GetPricingSchemeResponse] `json:"pricing_scheme"`
Discounts types.Optional[[]GetDiscountResponse] `json:"discounts"`
Increments types.Optional[[]GetIncrementResponse] `json:"increments"`
Subscription types.Optional[GetSubscriptionResponse] `json:"subscription"`
Name types.Optional[string] `json:"name"`
Quantity types.Optional[int] `json:"quantity"`
Cycles types.Optional[int] `json:"cycles"`
DeletedAt types.Optional[time.Time] `json:"deleted_at"`
}
func (g *GetSubscriptionItemResponse) MarshalJSON() (
[]byte,
error) {
return json.Marshal(g.toMap())
}
func (g *GetSubscriptionItemResponse) toMap() map[string]any {
structMap := make(map[string]any)
if g.Id.IsValueSet() {
structMap["id"] = g.Id.Value()
}
if g.Description.IsValueSet() {
structMap["description"] = g.Description.Value()
}
if g.Status.IsValueSet() {
structMap["status"] = g.Status.Value()
}
if g.CreatedAt.IsValueSet() {
var CreatedAtVal *string = nil
if g.CreatedAt.Value() != nil {
val := g.CreatedAt.Value().Format(time.RFC3339)
CreatedAtVal = &val
}
structMap["created_at"] = CreatedAtVal
}
if g.UpdatedAt.IsValueSet() {
var UpdatedAtVal *string = nil
if g.UpdatedAt.Value() != nil {
val := g.UpdatedAt.Value().Format(time.RFC3339)
UpdatedAtVal = &val
}
structMap["updated_at"] = UpdatedAtVal
}
if g.PricingScheme.IsValueSet() {
structMap["pricing_scheme"] = g.PricingScheme.Value()
}
if g.Discounts.IsValueSet() {
structMap["discounts"] = g.Discounts.Value()
}
if g.Increments.IsValueSet() {
structMap["increments"] = g.Increments.Value()
}
if g.Subscription.IsValueSet() {
structMap["subscription"] = g.Subscription.Value()
}
if g.Name.IsValueSet() {
structMap["name"] = g.Name.Value()
}
if g.Quantity.IsValueSet() {
structMap["quantity"] = g.Quantity.Value()
}
if g.Cycles.IsValueSet() {
structMap["cycles"] = g.Cycles.Value()
}
if g.DeletedAt.IsValueSet() {
var DeletedAtVal *string = nil
if g.DeletedAt.Value() != nil {
val := g.DeletedAt.Value().Format(time.RFC3339)
DeletedAtVal = &val
}
structMap["deleted_at"] = DeletedAtVal
}
return structMap
}
func (g *GetSubscriptionItemResponse) UnmarshalJSON(input []byte) error {
temp := &struct {
Id types.Optional[string] `json:"id"`
Description types.Optional[string] `json:"description"`
Status types.Optional[string] `json:"status"`
CreatedAt types.Optional[string] `json:"created_at"`
UpdatedAt types.Optional[string] `json:"updated_at"`
PricingScheme types.Optional[GetPricingSchemeResponse] `json:"pricing_scheme"`
Discounts types.Optional[[]GetDiscountResponse] `json:"discounts"`
Increments types.Optional[[]GetIncrementResponse] `json:"increments"`
Subscription types.Optional[GetSubscriptionResponse] `json:"subscription"`
Name types.Optional[string] `json:"name"`
Quantity types.Optional[int] `json:"quantity"`
Cycles types.Optional[int] `json:"cycles"`
DeletedAt types.Optional[string] `json:"deleted_at"`
}{}
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
g.Id = temp.Id
g.Description = temp.Description
g.Status = temp.Status
g.CreatedAt.ShouldSetValue(temp.CreatedAt.IsValueSet())
if temp.CreatedAt.Value() != nil {
CreatedAtVal, err := time.Parse(time.RFC3339, (*temp.CreatedAt.Value()))
if err != nil {
log.Fatalf("Cannot Parse created_at as % s format.", time.RFC3339)
}
g.CreatedAt.SetValue(&CreatedAtVal)
}
g.UpdatedAt.ShouldSetValue(temp.UpdatedAt.IsValueSet())
if temp.UpdatedAt.Value() != nil {
UpdatedAtVal, err := time.Parse(time.RFC3339, (*temp.UpdatedAt.Value()))
if err != nil {
log.Fatalf("Cannot Parse updated_at as % s format.", time.RFC3339)
}
g.UpdatedAt.SetValue(&UpdatedAtVal)
}
g.PricingScheme = temp.PricingScheme
g.Discounts = temp.Discounts
g.Increments = temp.Increments
g.Subscription = temp.Subscription
g.Name = temp.Name
g.Quantity = temp.Quantity
g.Cycles = temp.Cycles
g.DeletedAt.ShouldSetValue(temp.DeletedAt.IsValueSet())
if temp.DeletedAt.Value() != nil {
DeletedAtVal, err := time.Parse(time.RFC3339, (*temp.DeletedAt.Value()))
if err != nil {
log.Fatalf("Cannot Parse deleted_at as % s format.", time.RFC3339)
}
g.DeletedAt.SetValue(&DeletedAtVal)
}
return nil
}