-
Notifications
You must be signed in to change notification settings - Fork 1
/
apply_debit_note_event.go
102 lines (94 loc) · 3.56 KB
/
apply_debit_note_event.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
package models
import (
"encoding/json"
"errors"
"log"
"strings"
"time"
)
// ApplyDebitNoteEvent represents a ApplyDebitNoteEvent struct.
type ApplyDebitNoteEvent struct {
Id int64 `json:"id"`
Timestamp time.Time `json:"timestamp"`
Invoice Invoice `json:"invoice"`
EventType InvoiceEventType `json:"event_type"`
// Example schema for an `apply_debit_note` event
EventData ApplyDebitNoteEventData `json:"event_data"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for ApplyDebitNoteEvent.
// It customizes the JSON marshaling process for ApplyDebitNoteEvent objects.
func (a ApplyDebitNoteEvent) MarshalJSON() (
[]byte,
error) {
return json.Marshal(a.toMap())
}
// toMap converts the ApplyDebitNoteEvent object to a map representation for JSON marshaling.
func (a ApplyDebitNoteEvent) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, a.AdditionalProperties)
structMap["id"] = a.Id
structMap["timestamp"] = a.Timestamp.Format(time.RFC3339)
structMap["invoice"] = a.Invoice.toMap()
structMap["event_type"] = a.EventType
structMap["event_data"] = a.EventData.toMap()
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for ApplyDebitNoteEvent.
// It customizes the JSON unmarshaling process for ApplyDebitNoteEvent objects.
func (a *ApplyDebitNoteEvent) UnmarshalJSON(input []byte) error {
var temp applyDebitNoteEvent
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
err = temp.validate()
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "id", "timestamp", "invoice", "event_type", "event_data")
if err != nil {
return err
}
a.AdditionalProperties = additionalProperties
a.Id = *temp.Id
TimestampVal, err := time.Parse(time.RFC3339, *temp.Timestamp)
if err != nil {
log.Fatalf("Cannot Parse timestamp as % s format.", time.RFC3339)
}
a.Timestamp = TimestampVal
a.Invoice = *temp.Invoice
a.EventType = *temp.EventType
a.EventData = *temp.EventData
return nil
}
// applyDebitNoteEvent is a temporary struct used for validating the fields of ApplyDebitNoteEvent.
type applyDebitNoteEvent struct {
Id *int64 `json:"id"`
Timestamp *string `json:"timestamp"`
Invoice *Invoice `json:"invoice"`
EventType *InvoiceEventType `json:"event_type"`
EventData *ApplyDebitNoteEventData `json:"event_data"`
}
func (a *applyDebitNoteEvent) validate() error {
var errs []string
if a.Id == nil {
errs = append(errs, "required field `id` is missing for type `Apply Debit Note Event`")
}
if a.Timestamp == nil {
errs = append(errs, "required field `timestamp` is missing for type `Apply Debit Note Event`")
}
if a.Invoice == nil {
errs = append(errs, "required field `invoice` is missing for type `Apply Debit Note Event`")
}
if a.EventType == nil {
errs = append(errs, "required field `event_type` is missing for type `Apply Debit Note Event`")
}
if a.EventData == nil {
errs = append(errs, "required field `event_data` is missing for type `Apply Debit Note Event`")
}
if len(errs) == 0 {
return nil
}
return errors.New(strings.Join(errs, "\n"))
}