-
Notifications
You must be signed in to change notification settings - Fork 1
/
coupon_restriction.go
80 lines (73 loc) · 2.55 KB
/
coupon_restriction.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
package models
import (
"encoding/json"
)
// CouponRestriction represents a CouponRestriction struct.
type CouponRestriction struct {
Id *int `json:"id,omitempty"`
ItemType *RestrictionType `json:"item_type,omitempty"`
ItemId *int `json:"item_id,omitempty"`
Name *string `json:"name,omitempty"`
Handle Optional[string] `json:"handle"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for CouponRestriction.
// It customizes the JSON marshaling process for CouponRestriction objects.
func (c CouponRestriction) MarshalJSON() (
[]byte,
error) {
return json.Marshal(c.toMap())
}
// toMap converts the CouponRestriction object to a map representation for JSON marshaling.
func (c CouponRestriction) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, c.AdditionalProperties)
if c.Id != nil {
structMap["id"] = c.Id
}
if c.ItemType != nil {
structMap["item_type"] = c.ItemType
}
if c.ItemId != nil {
structMap["item_id"] = c.ItemId
}
if c.Name != nil {
structMap["name"] = c.Name
}
if c.Handle.IsValueSet() {
if c.Handle.Value() != nil {
structMap["handle"] = c.Handle.Value()
} else {
structMap["handle"] = nil
}
}
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for CouponRestriction.
// It customizes the JSON unmarshaling process for CouponRestriction objects.
func (c *CouponRestriction) UnmarshalJSON(input []byte) error {
var temp couponRestriction
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "id", "item_type", "item_id", "name", "handle")
if err != nil {
return err
}
c.AdditionalProperties = additionalProperties
c.Id = temp.Id
c.ItemType = temp.ItemType
c.ItemId = temp.ItemId
c.Name = temp.Name
c.Handle = temp.Handle
return nil
}
// couponRestriction is a temporary struct used for validating the fields of CouponRestriction.
type couponRestriction struct {
Id *int `json:"id,omitempty"`
ItemType *RestrictionType `json:"item_type,omitempty"`
ItemId *int `json:"item_id,omitempty"`
Name *string `json:"name,omitempty"`
Handle Optional[string] `json:"handle"`
}