This repository has been archived by the owner on Sep 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
foreignborndocument.go
105 lines (90 loc) · 3.32 KB
/
foreignborndocument.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
package api
import "encoding/json"
// ForeignBornDocument is a basic input.
type ForeignBornDocument struct {
PayloadDocumentType Payload `json:"DocumentType" sql:"-"`
PayloadOtherExplanation Payload `json:"OtherExplanation" sql:"-"`
PayloadDocumentNumber Payload `json:"DocumentNumber" sql:"-"`
PayloadDocumentExpiration Payload `json:"DocumentExpiration" sql:"-"`
PayloadDocumentExpirationNotApplicable Payload `json:"DocumentExpirationNotApplicable" sql:"-"`
// Validator specific fields
DocumentType *Radio `json:"-"`
OtherExplanation *Textarea `json:"-"`
DocumentNumber *Text `json:"-"`
DocumentExpiration *DateControl `json:"-"`
DocumentExpirationNotApplicable *NotApplicable `json:"-"`
// Persister specific fields
ID int `json:"-"`
AccountID int `json:"-"`
DocumentTypeID int `json:"-"`
OtherExplanationID int `json:"-"`
DocumentNumberID int `json:"-"`
DocumentExpirationID int `json:"-"`
DocumentExpirationNotApplicableID int `json:"-"`
}
// Unmarshal bytes in to the entity properties.
func (entity *ForeignBornDocument) Unmarshal(raw []byte) error {
err := json.Unmarshal(raw, entity)
if err != nil {
return err
}
documentType, err := entity.PayloadDocumentType.Entity()
if err != nil {
return err
}
entity.DocumentType = documentType.(*Radio)
otherExplanation, err := entity.PayloadOtherExplanation.Entity()
if err != nil {
return err
}
entity.OtherExplanation = otherExplanation.(*Textarea)
documentNumber, err := entity.PayloadDocumentNumber.Entity()
if err != nil {
return err
}
entity.DocumentNumber = documentNumber.(*Text)
documentExpiration, err := entity.PayloadDocumentExpiration.Entity()
if err != nil {
return err
}
entity.DocumentExpiration = documentExpiration.(*DateControl)
documentExpirationNotApplicable, err := entity.PayloadDocumentExpirationNotApplicable.Entity()
if err != nil {
return err
}
entity.DocumentExpirationNotApplicable = documentExpirationNotApplicable.(*NotApplicable)
return err
}
// Marshal to payload structure
func (entity *ForeignBornDocument) Marshal() Payload {
if entity.DocumentType != nil {
entity.PayloadDocumentType = entity.DocumentType.Marshal()
}
if entity.OtherExplanation != nil {
entity.PayloadOtherExplanation = entity.OtherExplanation.Marshal()
}
if entity.DocumentNumber != nil {
entity.PayloadDocumentNumber = entity.DocumentNumber.Marshal()
}
if entity.DocumentExpiration != nil {
entity.PayloadDocumentExpiration = entity.DocumentExpiration.Marshal()
}
if entity.DocumentExpirationNotApplicable != nil {
entity.PayloadDocumentExpirationNotApplicable = entity.DocumentExpirationNotApplicable.Marshal()
}
return MarshalPayloadEntity("foreignborndocument", entity)
}
// Valid checks the value(s) against an battery of tests.
func (entity *ForeignBornDocument) Valid() (bool, error) {
if entity.DocumentType.Value == "Other" {
if ok, err := entity.OtherExplanation.Valid(); !ok {
return false, err
}
}
if entity.DocumentExpirationNotApplicable.Applicable {
if ok, err := entity.DocumentNumber.Valid(); !ok {
return false, err
}
}
return true, nil
}