-
Notifications
You must be signed in to change notification settings - Fork 1
/
metafield_scope.go
95 lines (88 loc) · 3.53 KB
/
metafield_scope.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
package models
import (
"encoding/json"
)
// MetafieldScope represents a MetafieldScope struct.
// Warning: When updating a metafield's scope attribute, all scope attributes must be passed. Partially complete scope attributes will override the existing settings.
type MetafieldScope struct {
// Include (1) or exclude (0) metafields from the csv export.
Csv *IncludeOption `json:"csv,omitempty"`
// Include (1) or exclude (0) metafields from invoices.
Invoices *IncludeOption `json:"invoices,omitempty"`
// Include (1) or exclude (0) metafields from statements.
Statements *IncludeOption `json:"statements,omitempty"`
// Include (1) or exclude (0) metafields from the portal.
Portal *IncludeOption `json:"portal,omitempty"`
// Include (1) or exclude (0) metafields from being viewable by your ecosystem.
PublicShow *IncludeOption `json:"public_show,omitempty"`
// Include (1) or exclude (0) metafields from being edited by your ecosystem.
PublicEdit *IncludeOption `json:"public_edit,omitempty"`
Hosted []string `json:"hosted,omitempty"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for MetafieldScope.
// It customizes the JSON marshaling process for MetafieldScope objects.
func (m MetafieldScope) MarshalJSON() (
[]byte,
error) {
return json.Marshal(m.toMap())
}
// toMap converts the MetafieldScope object to a map representation for JSON marshaling.
func (m MetafieldScope) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, m.AdditionalProperties)
if m.Csv != nil {
structMap["csv"] = m.Csv
}
if m.Invoices != nil {
structMap["invoices"] = m.Invoices
}
if m.Statements != nil {
structMap["statements"] = m.Statements
}
if m.Portal != nil {
structMap["portal"] = m.Portal
}
if m.PublicShow != nil {
structMap["public_show"] = m.PublicShow
}
if m.PublicEdit != nil {
structMap["public_edit"] = m.PublicEdit
}
if m.Hosted != nil {
structMap["hosted"] = m.Hosted
}
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for MetafieldScope.
// It customizes the JSON unmarshaling process for MetafieldScope objects.
func (m *MetafieldScope) UnmarshalJSON(input []byte) error {
var temp metafieldScope
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "csv", "invoices", "statements", "portal", "public_show", "public_edit", "hosted")
if err != nil {
return err
}
m.AdditionalProperties = additionalProperties
m.Csv = temp.Csv
m.Invoices = temp.Invoices
m.Statements = temp.Statements
m.Portal = temp.Portal
m.PublicShow = temp.PublicShow
m.PublicEdit = temp.PublicEdit
m.Hosted = temp.Hosted
return nil
}
// metafieldScope is a temporary struct used for validating the fields of MetafieldScope.
type metafieldScope struct {
Csv *IncludeOption `json:"csv,omitempty"`
Invoices *IncludeOption `json:"invoices,omitempty"`
Statements *IncludeOption `json:"statements,omitempty"`
Portal *IncludeOption `json:"portal,omitempty"`
PublicShow *IncludeOption `json:"public_show,omitempty"`
PublicEdit *IncludeOption `json:"public_edit,omitempty"`
Hosted []string `json:"hosted,omitempty"`
}