-
Notifications
You must be signed in to change notification settings - Fork 2
/
attorney.go
163 lines (130 loc) · 3.4 KB
/
attorney.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
package actor
import (
"fmt"
"slices"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid"
"github.com/ministryofjustice/opg-modernising-lpa/internal/date"
"github.com/ministryofjustice/opg-modernising-lpa/internal/place"
)
// Attorney contains details about an attorney or replacement attorney, provided by the applicant
type Attorney struct {
// UID for the actor
UID actoruid.UID
// First names of the attorney
FirstNames string
// Last name of the attorney
LastName string
// Email of the attorney
Email string
// Date of birth of the attorney
DateOfBirth date.Date
// Address of the attorney
Address place.Address
}
func (a Attorney) FullName() string {
return fmt.Sprintf("%s %s", a.FirstNames, a.LastName)
}
func (a Attorney) Channel() Channel {
if a.Email != "" {
return ChannelOnline
}
return ChannelPaper
}
// TrustCorporation contains details about a trust corporation, provided by the applicant
type TrustCorporation struct {
// UID for the actor
UID actoruid.UID
// Name of the company
Name string
// CompanyNumber as registered by Companies House
CompanyNumber string
// Email to contact the company
Email string
// Address of the company
Address place.Address
}
func (tc TrustCorporation) Channel() Channel {
if tc.Email != "" {
return ChannelOnline
}
return ChannelPaper
}
type Attorneys struct {
TrustCorporation TrustCorporation
Attorneys []Attorney
}
func (as Attorneys) Len() int {
if as.TrustCorporation.Name == "" {
return len(as.Attorneys)
}
return len(as.Attorneys) + 1
}
func (as Attorneys) Complete() bool {
if as.TrustCorporation.Name != "" && as.TrustCorporation.Address.Line1 == "" {
return false
}
for _, a := range as.Attorneys {
if a.FirstNames == "" || (a.Address.Line1 == "" && a.Email == "") {
return false
}
}
return true
}
func (as Attorneys) Addresses() []place.Address {
var addresses []place.Address
if as.TrustCorporation.Address.String() != "" {
addresses = append(addresses, as.TrustCorporation.Address)
}
for _, attorney := range as.Attorneys {
if attorney.Address.String() != "" && !slices.Contains(addresses, attorney.Address) {
addresses = append(addresses, attorney.Address)
}
}
return addresses
}
func (as Attorneys) Get(uid actoruid.UID) (Attorney, bool) {
idx := as.Index(uid)
if idx == -1 {
return Attorney{}, false
}
return as.Attorneys[idx], true
}
func (as *Attorneys) Put(attorney Attorney) {
idx := as.Index(attorney.UID)
if idx == -1 {
as.Attorneys = append(as.Attorneys, attorney)
} else {
as.Attorneys[idx] = attorney
}
}
func (as *Attorneys) Delete(attorney Attorney) bool {
idx := as.Index(attorney.UID)
if idx == -1 {
return false
}
as.Attorneys = slices.Delete(as.Attorneys, idx, idx+1)
return true
}
func (as *Attorneys) Index(uid actoruid.UID) int {
return slices.IndexFunc(as.Attorneys, func(a Attorney) bool { return a.UID == uid })
}
func (as Attorneys) FullNames() []string {
var names []string
if as.TrustCorporation.Name != "" {
names = append(names, as.TrustCorporation.Name)
}
for _, a := range as.Attorneys {
names = append(names, fmt.Sprintf("%s %s", a.FirstNames, a.LastName))
}
return names
}
func (as Attorneys) FirstNames() []string {
var names []string
if as.TrustCorporation.Name != "" {
names = append(names, as.TrustCorporation.Name)
}
for _, a := range as.Attorneys {
names = append(names, a.FirstNames)
}
return names
}