forked from labd/commercetools-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types_inventory.go
287 lines (257 loc) · 9.35 KB
/
types_inventory.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
// Automatically generated, do not edit
package commercetools
import (
"encoding/json"
"errors"
"time"
)
// InventoryEntryUpdateAction uses action as discriminator attribute
type InventoryEntryUpdateAction interface{}
func mapDiscriminatorInventoryEntryUpdateAction(input interface{}) (InventoryEntryUpdateAction, error) {
var discriminator string
if data, ok := input.(map[string]interface{}); ok {
discriminator, ok = data["action"].(string)
if !ok {
return nil, errors.New("Error processing discriminator field 'action'")
}
} else {
return nil, errors.New("Invalid data")
}
switch discriminator {
case "addQuantity":
new := InventoryEntryAddQuantityAction{}
err := decodeStruct(input, &new)
if err != nil {
return nil, err
}
return new, nil
case "changeQuantity":
new := InventoryEntryChangeQuantityAction{}
err := decodeStruct(input, &new)
if err != nil {
return nil, err
}
return new, nil
case "removeQuantity":
new := InventoryEntryRemoveQuantityAction{}
err := decodeStruct(input, &new)
if err != nil {
return nil, err
}
return new, nil
case "setCustomField":
new := InventoryEntrySetCustomFieldAction{}
err := decodeStruct(input, &new)
if err != nil {
return nil, err
}
return new, nil
case "setCustomType":
new := InventoryEntrySetCustomTypeAction{}
err := decodeStruct(input, &new)
if err != nil {
return nil, err
}
return new, nil
case "setExpectedDelivery":
new := InventoryEntrySetExpectedDeliveryAction{}
err := decodeStruct(input, &new)
if err != nil {
return nil, err
}
return new, nil
case "setRestockableInDays":
new := InventoryEntrySetRestockableInDaysAction{}
err := decodeStruct(input, &new)
if err != nil {
return nil, err
}
return new, nil
case "setSupplyChannel":
new := InventoryEntrySetSupplyChannelAction{}
err := decodeStruct(input, &new)
if err != nil {
return nil, err
}
return new, nil
}
return nil, nil
}
// InventoryEntry is of type BaseResource
type InventoryEntry struct {
Version int `json:"version"`
SupplyChannel *ChannelResourceIdentifier `json:"supplyChannel,omitempty"`
SKU string `json:"sku"`
RestockableInDays int `json:"restockableInDays,omitempty"`
QuantityOnStock int `json:"quantityOnStock"`
LastModifiedBy *LastModifiedBy `json:"lastModifiedBy,omitempty"`
LastModifiedAt time.Time `json:"lastModifiedAt"`
ID string `json:"id"`
ExpectedDelivery *time.Time `json:"expectedDelivery,omitempty"`
Custom *CustomFields `json:"custom,omitempty"`
CreatedBy *CreatedBy `json:"createdBy,omitempty"`
CreatedAt time.Time `json:"createdAt"`
AvailableQuantity int `json:"availableQuantity"`
}
// InventoryEntryAddQuantityAction implements the interface InventoryEntryUpdateAction
type InventoryEntryAddQuantityAction struct {
Quantity int `json:"quantity"`
}
// MarshalJSON override to set the discriminator value
func (obj InventoryEntryAddQuantityAction) MarshalJSON() ([]byte, error) {
type Alias InventoryEntryAddQuantityAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "addQuantity", Alias: (*Alias)(&obj)})
}
// InventoryEntryChangeQuantityAction implements the interface InventoryEntryUpdateAction
type InventoryEntryChangeQuantityAction struct {
Quantity int `json:"quantity"`
}
// MarshalJSON override to set the discriminator value
func (obj InventoryEntryChangeQuantityAction) MarshalJSON() ([]byte, error) {
type Alias InventoryEntryChangeQuantityAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "changeQuantity", Alias: (*Alias)(&obj)})
}
// InventoryEntryDraft is a standalone struct
type InventoryEntryDraft struct {
SupplyChannel *ChannelResourceIdentifier `json:"supplyChannel,omitempty"`
SKU string `json:"sku"`
RestockableInDays int `json:"restockableInDays,omitempty"`
QuantityOnStock int `json:"quantityOnStock"`
ExpectedDelivery *time.Time `json:"expectedDelivery,omitempty"`
Custom *CustomFieldsDraft `json:"custom,omitempty"`
}
// InventoryEntryReference implements the interface Reference
type InventoryEntryReference struct {
ID string `json:"id"`
Obj *InventoryEntry `json:"obj,omitempty"`
}
// MarshalJSON override to set the discriminator value
func (obj InventoryEntryReference) MarshalJSON() ([]byte, error) {
type Alias InventoryEntryReference
return json.Marshal(struct {
TypeID string `json:"typeId"`
*Alias
}{TypeID: "inventory-entry", Alias: (*Alias)(&obj)})
}
// InventoryEntryRemoveQuantityAction implements the interface InventoryEntryUpdateAction
type InventoryEntryRemoveQuantityAction struct {
Quantity int `json:"quantity"`
}
// MarshalJSON override to set the discriminator value
func (obj InventoryEntryRemoveQuantityAction) MarshalJSON() ([]byte, error) {
type Alias InventoryEntryRemoveQuantityAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "removeQuantity", Alias: (*Alias)(&obj)})
}
// InventoryEntryResourceIdentifier implements the interface ResourceIdentifier
type InventoryEntryResourceIdentifier struct {
Key string `json:"key,omitempty"`
ID string `json:"id,omitempty"`
}
// MarshalJSON override to set the discriminator value
func (obj InventoryEntryResourceIdentifier) MarshalJSON() ([]byte, error) {
type Alias InventoryEntryResourceIdentifier
return json.Marshal(struct {
TypeID string `json:"typeId"`
*Alias
}{TypeID: "inventory-entry", Alias: (*Alias)(&obj)})
}
// InventoryEntrySetCustomFieldAction implements the interface InventoryEntryUpdateAction
type InventoryEntrySetCustomFieldAction struct {
Value interface{} `json:"value,omitempty"`
Name string `json:"name"`
}
// MarshalJSON override to set the discriminator value
func (obj InventoryEntrySetCustomFieldAction) MarshalJSON() ([]byte, error) {
type Alias InventoryEntrySetCustomFieldAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "setCustomField", Alias: (*Alias)(&obj)})
}
// InventoryEntrySetCustomTypeAction implements the interface InventoryEntryUpdateAction
type InventoryEntrySetCustomTypeAction struct {
Type *TypeResourceIdentifier `json:"type,omitempty"`
Fields *FieldContainer `json:"fields,omitempty"`
}
// MarshalJSON override to set the discriminator value
func (obj InventoryEntrySetCustomTypeAction) MarshalJSON() ([]byte, error) {
type Alias InventoryEntrySetCustomTypeAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "setCustomType", Alias: (*Alias)(&obj)})
}
// InventoryEntrySetExpectedDeliveryAction implements the interface InventoryEntryUpdateAction
type InventoryEntrySetExpectedDeliveryAction struct {
ExpectedDelivery *time.Time `json:"expectedDelivery,omitempty"`
}
// MarshalJSON override to set the discriminator value
func (obj InventoryEntrySetExpectedDeliveryAction) MarshalJSON() ([]byte, error) {
type Alias InventoryEntrySetExpectedDeliveryAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "setExpectedDelivery", Alias: (*Alias)(&obj)})
}
// InventoryEntrySetRestockableInDaysAction implements the interface InventoryEntryUpdateAction
type InventoryEntrySetRestockableInDaysAction struct {
RestockableInDays int `json:"restockableInDays,omitempty"`
}
// MarshalJSON override to set the discriminator value
func (obj InventoryEntrySetRestockableInDaysAction) MarshalJSON() ([]byte, error) {
type Alias InventoryEntrySetRestockableInDaysAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "setRestockableInDays", Alias: (*Alias)(&obj)})
}
// InventoryEntrySetSupplyChannelAction implements the interface InventoryEntryUpdateAction
type InventoryEntrySetSupplyChannelAction struct {
SupplyChannel *ChannelResourceIdentifier `json:"supplyChannel,omitempty"`
}
// MarshalJSON override to set the discriminator value
func (obj InventoryEntrySetSupplyChannelAction) MarshalJSON() ([]byte, error) {
type Alias InventoryEntrySetSupplyChannelAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "setSupplyChannel", Alias: (*Alias)(&obj)})
}
// InventoryEntryUpdate is a standalone struct
type InventoryEntryUpdate struct {
Version int `json:"version"`
Actions []InventoryEntryUpdateAction `json:"actions"`
}
// UnmarshalJSON override to deserialize correct attribute types based
// on the discriminator value
func (obj *InventoryEntryUpdate) UnmarshalJSON(data []byte) error {
type Alias InventoryEntryUpdate
if err := json.Unmarshal(data, (*Alias)(obj)); err != nil {
return err
}
for i := range obj.Actions {
var err error
obj.Actions[i], err = mapDiscriminatorInventoryEntryUpdateAction(obj.Actions[i])
if err != nil {
return err
}
}
return nil
}
// InventoryPagedQueryResponse is a standalone struct
type InventoryPagedQueryResponse struct {
Total int `json:"total,omitempty"`
Results []InventoryEntry `json:"results"`
Offset int `json:"offset"`
Limit int `json:"limit"`
Count int `json:"count"`
}