-
Notifications
You must be signed in to change notification settings - Fork 1
/
invoice_issued.go
176 lines (168 loc) · 7.22 KB
/
invoice_issued.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
package models
import (
"encoding/json"
"errors"
"log"
"strings"
"time"
)
// InvoiceIssued represents a InvoiceIssued struct.
type InvoiceIssued struct {
Uid string `json:"uid"`
Number string `json:"number"`
Role string `json:"role"`
DueDate *time.Time `json:"due_date"`
// Invoice issue date. Can be an empty string if value is missing.
IssueDate string `json:"issue_date"`
// Paid date. Can be an empty string if value is missing.
PaidDate string `json:"paid_date"`
DueAmount string `json:"due_amount"`
PaidAmount string `json:"paid_amount"`
TaxAmount string `json:"tax_amount"`
RefundAmount string `json:"refund_amount"`
TotalAmount string `json:"total_amount"`
StatusAmount string `json:"status_amount"`
ProductName string `json:"product_name"`
ConsolidationLevel string `json:"consolidation_level"`
LineItems []InvoiceLineItemEventData `json:"line_items"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for InvoiceIssued.
// It customizes the JSON marshaling process for InvoiceIssued objects.
func (i InvoiceIssued) MarshalJSON() (
[]byte,
error) {
return json.Marshal(i.toMap())
}
// toMap converts the InvoiceIssued object to a map representation for JSON marshaling.
func (i InvoiceIssued) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, i.AdditionalProperties)
structMap["uid"] = i.Uid
structMap["number"] = i.Number
structMap["role"] = i.Role
if i.DueDate != nil {
structMap["due_date"] = i.DueDate.Format(DEFAULT_DATE)
} else {
structMap["due_date"] = nil
}
structMap["issue_date"] = i.IssueDate
structMap["paid_date"] = i.PaidDate
structMap["due_amount"] = i.DueAmount
structMap["paid_amount"] = i.PaidAmount
structMap["tax_amount"] = i.TaxAmount
structMap["refund_amount"] = i.RefundAmount
structMap["total_amount"] = i.TotalAmount
structMap["status_amount"] = i.StatusAmount
structMap["product_name"] = i.ProductName
structMap["consolidation_level"] = i.ConsolidationLevel
structMap["line_items"] = i.LineItems
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for InvoiceIssued.
// It customizes the JSON unmarshaling process for InvoiceIssued objects.
func (i *InvoiceIssued) UnmarshalJSON(input []byte) error {
var temp invoiceIssued
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
err = temp.validate()
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "uid", "number", "role", "due_date", "issue_date", "paid_date", "due_amount", "paid_amount", "tax_amount", "refund_amount", "total_amount", "status_amount", "product_name", "consolidation_level", "line_items")
if err != nil {
return err
}
i.AdditionalProperties = additionalProperties
i.Uid = *temp.Uid
i.Number = *temp.Number
i.Role = *temp.Role
if temp.DueDate != nil {
DueDateVal, err := time.Parse(DEFAULT_DATE, *temp.DueDate)
if err != nil {
log.Fatalf("Cannot Parse due_date as % s format.", DEFAULT_DATE)
}
i.DueDate = &DueDateVal
}
i.IssueDate = *temp.IssueDate
i.PaidDate = *temp.PaidDate
i.DueAmount = *temp.DueAmount
i.PaidAmount = *temp.PaidAmount
i.TaxAmount = *temp.TaxAmount
i.RefundAmount = *temp.RefundAmount
i.TotalAmount = *temp.TotalAmount
i.StatusAmount = *temp.StatusAmount
i.ProductName = *temp.ProductName
i.ConsolidationLevel = *temp.ConsolidationLevel
i.LineItems = *temp.LineItems
return nil
}
// invoiceIssued is a temporary struct used for validating the fields of InvoiceIssued.
type invoiceIssued struct {
Uid *string `json:"uid"`
Number *string `json:"number"`
Role *string `json:"role"`
DueDate *string `json:"due_date"`
IssueDate *string `json:"issue_date"`
PaidDate *string `json:"paid_date"`
DueAmount *string `json:"due_amount"`
PaidAmount *string `json:"paid_amount"`
TaxAmount *string `json:"tax_amount"`
RefundAmount *string `json:"refund_amount"`
TotalAmount *string `json:"total_amount"`
StatusAmount *string `json:"status_amount"`
ProductName *string `json:"product_name"`
ConsolidationLevel *string `json:"consolidation_level"`
LineItems *[]InvoiceLineItemEventData `json:"line_items"`
}
func (i *invoiceIssued) validate() error {
var errs []string
if i.Uid == nil {
errs = append(errs, "required field `uid` is missing for type `Invoice Issued`")
}
if i.Number == nil {
errs = append(errs, "required field `number` is missing for type `Invoice Issued`")
}
if i.Role == nil {
errs = append(errs, "required field `role` is missing for type `Invoice Issued`")
}
if i.IssueDate == nil {
errs = append(errs, "required field `issue_date` is missing for type `Invoice Issued`")
}
if i.PaidDate == nil {
errs = append(errs, "required field `paid_date` is missing for type `Invoice Issued`")
}
if i.DueAmount == nil {
errs = append(errs, "required field `due_amount` is missing for type `Invoice Issued`")
}
if i.PaidAmount == nil {
errs = append(errs, "required field `paid_amount` is missing for type `Invoice Issued`")
}
if i.TaxAmount == nil {
errs = append(errs, "required field `tax_amount` is missing for type `Invoice Issued`")
}
if i.RefundAmount == nil {
errs = append(errs, "required field `refund_amount` is missing for type `Invoice Issued`")
}
if i.TotalAmount == nil {
errs = append(errs, "required field `total_amount` is missing for type `Invoice Issued`")
}
if i.StatusAmount == nil {
errs = append(errs, "required field `status_amount` is missing for type `Invoice Issued`")
}
if i.ProductName == nil {
errs = append(errs, "required field `product_name` is missing for type `Invoice Issued`")
}
if i.ConsolidationLevel == nil {
errs = append(errs, "required field `consolidation_level` is missing for type `Invoice Issued`")
}
if i.LineItems == nil {
errs = append(errs, "required field `line_items` is missing for type `Invoice Issued`")
}
if len(errs) == 0 {
return nil
}
return errors.New(strings.Join(errs, "\n"))
}