From 953027a8747a88d319d33c90306898361d7b4148 Mon Sep 17 00:00:00 2001 From: Joshua Hawxwell Date: Mon, 29 Jul 2024 15:22:32 +0100 Subject: [PATCH] Move donor data types out of actor into own package (#1384) --- internal/actor/attorney.go | 162 +------ internal/actor/attorney_decisions.go | 50 +-- internal/actor/can_be_used_when.go | 11 +- internal/actor/certificate_provider.go | 49 +-- internal/actor/channel.go | 9 +- internal/actor/correspondent.go | 25 +- internal/actor/donor.go | 64 +-- internal/actor/donor_provided.go | 407 +---------------- internal/actor/enum_novoucherdecision.go | 3 - internal/actor/life_sustaining_treatment.go | 9 +- internal/actor/limiter.go | 44 +- internal/actor/lpa_type.go | 19 +- internal/actor/payment.go | 11 +- internal/actor/person_to_notify.go | 53 +-- .../actor/replacement_attorneys_step_in.go | 11 +- internal/actor/task_state_test.go | 33 -- internal/actor/voucher.go | 55 +-- internal/actor/witness_codes.go | 43 +- internal/actor/yes_no_maybe.go | 11 +- internal/donor/donordata/attorney.go | 37 ++ .../donor/donordata/attorney_decisions.go | 49 +++ .../donordata}/attorney_decisions_test.go | 2 +- .../donordata}/attorney_test.go | 2 +- internal/donor/donordata/attorneys.go | 112 +++++ .../donor/donordata/authorised_signatory.go | 13 + internal/donor/donordata/can_be_used_when.go | 10 + .../donordata}/can_be_used_when_test.go | 2 +- .../donor/donordata/certificate_provider.go | 53 +++ .../donordata}/certificate_provider_test.go | 2 +- internal/donor/donordata/channel.go | 9 + internal/donor/donordata/correspondent.go | 29 ++ .../donordata}/correspondent_test.go | 2 +- internal/donor/donordata/donor.go | 44 ++ .../donordata}/donor_provided_test.go | 7 +- .../{actor => donor/donordata}/donor_test.go | 2 +- .../donordata}/enum_attorneysact.go | 5 +- .../donordata}/enum_canbeusedwhen.go | 2 +- .../enum_certificateproviderrelationship.go | 5 +- ...m_certificateproviderrelationshiplength.go | 2 +- .../donordata}/enum_channel.go | 5 +- .../donordata}/enum_correspondentshare.go | 2 +- .../enum_lifesustainingtreatment.go | 5 +- .../donordata}/enum_lpatype.go | 5 +- .../enum_replacementattorneysstepin.go | 5 +- .../donordata}/enum_yesnomaybe.go | 5 +- .../donor/donordata/independent_witness.go | 20 + .../donordata/life_sustaining_treatment.go | 9 + .../life_sustaining_treatment_test.go | 2 +- internal/donor/donordata/limiter.go | 45 ++ .../donordata}/limiter_test.go | 2 +- internal/donor/donordata/lpa_type.go | 19 + .../donordata}/lpa_type_test.go | 2 +- .../donordata}/mock_Localizer_test.go | 2 +- internal/donor/donordata/payment.go | 10 + internal/donor/donordata/people_to_notify.go | 39 ++ internal/donor/donordata/person_to_notify.go | 21 + .../donordata}/person_to_notify_test.go | 2 +- internal/donor/donordata/provided.go | 412 ++++++++++++++++++ .../replacement_attorneys_step_in.go | 10 + .../replacement_attorneys_step_in_test.go | 2 +- internal/donor/donordata/trust_corporation.go | 28 ++ internal/donor/donordata/voucher.go | 60 +++ .../donordata}/voucher_test.go | 27 +- internal/donor/donordata/witness_codes.go | 43 ++ .../donordata}/witness_codes_test.go | 2 +- internal/donor/donordata/yes_no_maybe.go | 10 + internal/localize/enum_lang.go | 3 - internal/page/donor/can_you_sign_your_lpa.go | 7 +- .../page/donor/can_you_sign_your_lpa_test.go | 3 +- ...w_do_you_know_your_certificate_provider.go | 7 +- ...you_know_your_certificate_provider_test.go | 5 +- ...ong_have_you_known_certificate_provider.go | 7 +- ...ave_you_known_certificate_provider_test.go | 9 +- .../how_should_attorneys_make_decisions.go | 7 +- ...ow_should_attorneys_make_decisions_test.go | 5 +- ...ld_replacement_attorneys_make_decisions.go | 5 +- ...placement_attorneys_make_decisions_test.go | 5 +- ...ow_should_replacement_attorneys_step_in.go | 7 +- ...ould_replacement_attorneys_step_in_test.go | 5 +- ...provider_prefer_to_carry_out_their_role.go | 7 +- ...der_prefer_to_carry_out_their_role_test.go | 7 +- .../page/donor/life_sustaining_treatment.go | 7 +- .../donor/life_sustaining_treatment_test.go | 5 +- internal/page/donor/lpa_type.go | 7 +- internal/page/donor/lpa_type_test.go | 5 +- .../page/donor/when_can_the_lpa_be_used.go | 7 +- .../donor/when_can_the_lpa_be_used_test.go | 5 +- ...n_correspondents_details_be_shared_with.go | 7 +- ...respondents_details_be_shared_with_test.go | 5 +- internal/pay/enum_evidencedelivery.go | 3 - internal/pay/enum_previousfee.go | 3 - 91 files changed, 1283 insertions(+), 1112 deletions(-) delete mode 100644 internal/actor/task_state_test.go create mode 100644 internal/donor/donordata/attorney.go create mode 100644 internal/donor/donordata/attorney_decisions.go rename internal/{actor => donor/donordata}/attorney_decisions_test.go (98%) rename internal/{actor => donor/donordata}/attorney_test.go (99%) create mode 100644 internal/donor/donordata/attorneys.go create mode 100644 internal/donor/donordata/authorised_signatory.go create mode 100644 internal/donor/donordata/can_be_used_when.go rename internal/{actor => donor/donordata}/can_be_used_when_test.go (97%) create mode 100644 internal/donor/donordata/certificate_provider.go rename internal/{actor => donor/donordata}/certificate_provider_test.go (92%) create mode 100644 internal/donor/donordata/channel.go create mode 100644 internal/donor/donordata/correspondent.go rename internal/{actor => donor/donordata}/correspondent_test.go (92%) create mode 100644 internal/donor/donordata/donor.go rename internal/{actor => donor/donordata}/donor_provided_test.go (97%) rename internal/{actor => donor/donordata}/donor_test.go (97%) rename internal/{actor => donor/donordata}/enum_attorneysact.go (98%) rename internal/{actor => donor/donordata}/enum_canbeusedwhen.go (99%) rename internal/{actor => donor/donordata}/enum_certificateproviderrelationship.go (98%) rename internal/{actor => donor/donordata}/enum_certificateproviderrelationshiplength.go (99%) rename internal/{actor => donor/donordata}/enum_channel.go (97%) rename internal/{actor => donor/donordata}/enum_correspondentshare.go (99%) rename internal/{actor => donor/donordata}/enum_lifesustainingtreatment.go (97%) rename internal/{actor => donor/donordata}/enum_lpatype.go (97%) rename internal/{actor => donor/donordata}/enum_replacementattorneysstepin.go (98%) rename internal/{actor => donor/donordata}/enum_yesnomaybe.go (97%) create mode 100644 internal/donor/donordata/independent_witness.go create mode 100644 internal/donor/donordata/life_sustaining_treatment.go rename internal/{actor => donor/donordata}/life_sustaining_treatment_test.go (98%) create mode 100644 internal/donor/donordata/limiter.go rename internal/{actor => donor/donordata}/limiter_test.go (99%) create mode 100644 internal/donor/donordata/lpa_type.go rename internal/{actor => donor/donordata}/lpa_type_test.go (98%) rename internal/{actor => donor/donordata}/mock_Localizer_test.go (99%) create mode 100644 internal/donor/donordata/payment.go create mode 100644 internal/donor/donordata/people_to_notify.go create mode 100644 internal/donor/donordata/person_to_notify.go rename internal/{actor => donor/donordata}/person_to_notify_test.go (99%) create mode 100644 internal/donor/donordata/provided.go create mode 100644 internal/donor/donordata/replacement_attorneys_step_in.go rename internal/{actor => donor/donordata}/replacement_attorneys_step_in_test.go (98%) create mode 100644 internal/donor/donordata/trust_corporation.go create mode 100644 internal/donor/donordata/voucher.go rename internal/{actor => donor/donordata}/voucher_test.go (56%) create mode 100644 internal/donor/donordata/witness_codes.go rename internal/{actor => donor/donordata}/witness_codes_test.go (99%) create mode 100644 internal/donor/donordata/yes_no_maybe.go diff --git a/internal/actor/attorney.go b/internal/actor/attorney.go index 4dfdc6159a..d2635e8fbb 100644 --- a/internal/actor/attorney.go +++ b/internal/actor/attorney.go @@ -1,163 +1,9 @@ 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" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" ) -// 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 == "" { - 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 -} +type Attorney = donordata.Attorney +type TrustCorporation = donordata.TrustCorporation +type Attorneys = donordata.Attorneys diff --git a/internal/actor/attorney_decisions.go b/internal/actor/attorney_decisions.go index a041ab4588..d2aa8fceb6 100644 --- a/internal/actor/attorney_decisions.go +++ b/internal/actor/attorney_decisions.go @@ -1,49 +1,15 @@ package actor -//go:generate enumerator -type AttorneysAct -linecomment -empty -type AttorneysAct uint8 +import "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" -const ( - // Jointly indicates attorneys or replacement attorneys should act jointly - Jointly AttorneysAct = iota + 1 // jointly - - // JointlyAndSeverally indicates attorneys or replacement attorneys should act - // jointly and severally - JointlyAndSeverally // jointly-and-severally +type AttorneysAct = donordata.AttorneysAct - // JointlyForSomeSeverallyForOthers indicates attorneys or replacement - // attorneys should act jointly for some decisions, and jointly and severally - // for other decisions - JointlyForSomeSeverallyForOthers // jointly-for-some-severally-for-others +const ( + Jointly = donordata.Jointly + JointlyAndSeverally = donordata.JointlyAndSeverally + JointlyForSomeSeverallyForOthers = donordata.JointlyForSomeSeverallyForOthers ) -// AttorneyDecisions contains details about how an attorney or replacement attorney should act, provided by the applicant -type AttorneyDecisions struct { - // How attorneys should make decisions - How AttorneysAct - // Details on how attorneys should make decisions if acting jointly for some decisions, and jointly and severally for other decisions - Details string -} - -func MakeAttorneyDecisions(existing AttorneyDecisions, how AttorneysAct, details string) AttorneyDecisions { - if existing.How == how { - if how == JointlyForSomeSeverallyForOthers { - existing.Details = details - } - - return existing - } - - if how != JointlyForSomeSeverallyForOthers { - return AttorneyDecisions{How: how} - } - - return AttorneyDecisions{ - How: how, - Details: details, - } -} +type AttorneyDecisions = donordata.AttorneyDecisions -func (d AttorneyDecisions) IsComplete() bool { - return !d.How.Empty() -} +var MakeAttorneyDecisions = donordata.MakeAttorneyDecisions diff --git a/internal/actor/can_be_used_when.go b/internal/actor/can_be_used_when.go index a401478443..5ef70127a9 100644 --- a/internal/actor/can_be_used_when.go +++ b/internal/actor/can_be_used_when.go @@ -1,10 +1,11 @@ package actor -//go:generate enumerator -type CanBeUsedWhen -linecomment -trimprefix -type CanBeUsedWhen uint8 +import "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" + +type CanBeUsedWhen = donordata.CanBeUsedWhen const ( - CanBeUsedWhenUnknown CanBeUsedWhen = iota - CanBeUsedWhenCapacityLost // when-capacity-lost - CanBeUsedWhenHasCapacity // when-has-capacity + CanBeUsedWhenUnknown = donordata.CanBeUsedWhenUnknown + CanBeUsedWhenCapacityLost = donordata.CanBeUsedWhenCapacityLost + CanBeUsedWhenHasCapacity = donordata.CanBeUsedWhenHasCapacity ) diff --git a/internal/actor/certificate_provider.go b/internal/actor/certificate_provider.go index 5f8f220421..8bcfd36d50 100644 --- a/internal/actor/certificate_provider.go +++ b/internal/actor/certificate_provider.go @@ -1,53 +1,22 @@ package actor import ( - "fmt" - - "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" - "github.com/ministryofjustice/opg-modernising-lpa/internal/place" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" ) -//go:generate enumerator -type CertificateProviderRelationship -linecomment -empty -type CertificateProviderRelationship uint8 +type CertificateProviderRelationship = donordata.CertificateProviderRelationship const ( - Personally CertificateProviderRelationship = iota + 1 // personally - Professionally // professionally + Personally = donordata.Personally + Professionally = donordata.Professionally ) -//go:generate enumerator -type CertificateProviderRelationshipLength -linecomment -type CertificateProviderRelationshipLength uint8 +type CertificateProviderRelationshipLength = donordata.CertificateProviderRelationshipLength const ( - RelationshipLengthUnknown CertificateProviderRelationshipLength = iota // unknown - LessThanTwoYears // lt-2-years - GreaterThanEqualToTwoYears // gte-2-years + RelationshipLengthUnknown = donordata.RelationshipLengthUnknown + LessThanTwoYears = donordata.LessThanTwoYears + GreaterThanEqualToTwoYears = donordata.GreaterThanEqualToTwoYears ) -// CertificateProvider contains details about the certificate provider, provided by the applicant -type CertificateProvider struct { - // UID for the actor - UID actoruid.UID - // First names of the certificate provider - FirstNames string - // Last name of the certificate provider - LastName string - // Address of the certificate provider - Address place.Address - // Mobile number of the certificate provider, used to send witness codes - Mobile string - // HasNonUKMobile indicates whether the value of Mobile is a non-UK mobile number - HasNonUKMobile bool - // Email of the certificate provider - Email string - // How the certificate provider wants to perform their role (paper or online) - CarryOutBy Channel - // The certificate provider's relationship to the applicant - Relationship CertificateProviderRelationship - // Amount of time Relationship has been in place if Personally - RelationshipLength CertificateProviderRelationshipLength -} - -func (c CertificateProvider) FullName() string { - return fmt.Sprintf("%s %s", c.FirstNames, c.LastName) -} +type CertificateProvider = donordata.CertificateProvider diff --git a/internal/actor/channel.go b/internal/actor/channel.go index 4bbf921754..b31fa40d69 100644 --- a/internal/actor/channel.go +++ b/internal/actor/channel.go @@ -1,9 +1,10 @@ package actor -//go:generate enumerator -type Channel -linecomment -empty -trimprefix -type Channel uint8 +import "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" + +type Channel = donordata.Channel const ( - ChannelPaper Channel = iota + 1 // paper - ChannelOnline // online + ChannelPaper = donordata.ChannelPaper + ChannelOnline = donordata.ChannelOnline ) diff --git a/internal/actor/correspondent.go b/internal/actor/correspondent.go index 92d19483d7..df128ac8d2 100644 --- a/internal/actor/correspondent.go +++ b/internal/actor/correspondent.go @@ -1,29 +1,14 @@ package actor import ( - "github.com/ministryofjustice/opg-modernising-lpa/internal/form" - "github.com/ministryofjustice/opg-modernising-lpa/internal/place" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" ) -//go:generate enumerator -type CorrespondentShare -linecomment -trimprefix -empty -bits -type CorrespondentShare uint8 +type CorrespondentShare = donordata.CorrespondentShare const ( - CorrespondentShareAttorneys CorrespondentShare = 2 << iota - CorrespondentShareCertificateProvider + CorrespondentShareAttorneys = donordata.CorrespondentShareAttorneys + CorrespondentShareCertificateProvider = donordata.CorrespondentShareCertificateProvider ) -type Correspondent struct { - FirstNames string - LastName string - Email string - Organisation string - Telephone string - WantAddress form.YesNo - Address place.Address - Share CorrespondentShare -} - -func (c Correspondent) FullName() string { - return c.FirstNames + " " + c.LastName -} +type Correspondent = donordata.Correspondent diff --git a/internal/actor/donor.go b/internal/actor/donor.go index 85ae955b14..19a7fa54f2 100644 --- a/internal/actor/donor.go +++ b/internal/actor/donor.go @@ -1,67 +1,11 @@ package actor import ( - "fmt" - "strings" - - "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" - "github.com/ministryofjustice/opg-modernising-lpa/internal/date" - "github.com/ministryofjustice/opg-modernising-lpa/internal/form" - "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" - "github.com/ministryofjustice/opg-modernising-lpa/internal/place" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" ) -// Donor contains details about the donor, provided by the applicant -type Donor struct { - // UID for the actor - UID actoruid.UID - // First names of the donor - FirstNames string - // Last name of the donor - LastName string - // Email of the donor - Email string - // Other names the donor is known by - OtherNames string - // Date of birth of the donor - DateOfBirth date.Date - // Address of the donor - Address place.Address - // ThinksCanSign is what the donor thinks about their ability to sign online - ThinksCanSign YesNoMaybe - // CanSign is Yes if the donor has said they will sign online - CanSign form.YesNo - // Channel is how the Donor is applying for their LPA (paper or online) - Channel Channel - // ContactLanguagePreference is the language the donor prefers to receive notifications in - ContactLanguagePreference localize.Lang - // LpaLanguagePreference is the language the donor prefers to receive the registered LPA in - LpaLanguagePreference localize.Lang -} - -func (d Donor) FullName() string { - return strings.Trim(fmt.Sprintf("%s %s", d.FirstNames, d.LastName), " ") -} - -// AuthorisedSignatory contains details of the person who will sign the LPA on the donor's behalf -type AuthorisedSignatory struct { - FirstNames string - LastName string -} - -func (s AuthorisedSignatory) FullName() string { - return fmt.Sprintf("%s %s", s.FirstNames, s.LastName) -} +type Donor = donordata.Donor -// IndependentWitness contains details of the person who will also witness the signing of the LPA -type IndependentWitness struct { - FirstNames string - LastName string - HasNonUKMobile bool - Mobile string - Address place.Address -} +type AuthorisedSignatory = donordata.AuthorisedSignatory -func (w IndependentWitness) FullName() string { - return fmt.Sprintf("%s %s", w.FirstNames, w.LastName) -} +type IndependentWitness = donordata.IndependentWitness diff --git a/internal/actor/donor_provided.go b/internal/actor/donor_provided.go index 42203a229d..135e195cb2 100644 --- a/internal/actor/donor_provided.go +++ b/internal/actor/donor_provided.go @@ -1,410 +1,11 @@ package actor import ( - "errors" - "slices" - "strings" - "time" - - "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" - "github.com/ministryofjustice/opg-modernising-lpa/internal/date" - "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" - "github.com/ministryofjustice/opg-modernising-lpa/internal/form" - "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" - "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" - "github.com/ministryofjustice/opg-modernising-lpa/internal/place" - "github.com/mitchellh/hashstructure/v2" -) - -const ( - currentHashVersion uint8 = 0 - currentCheckedHashVersion uint8 = 0 + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" ) -type DonorTasks struct { - YourDetails TaskState - ChooseAttorneys TaskState - ChooseReplacementAttorneys TaskState - WhenCanTheLpaBeUsed TaskState // property and affairs only - LifeSustainingTreatment TaskState // personal welfare only - Restrictions TaskState - CertificateProvider TaskState - PeopleToNotify TaskState - AddCorrespondent TaskState - ChooseYourSignatory TaskState // if .Donor.CanSign.IsNo only - CheckYourLpa TaskState - PayForLpa PaymentTask - ConfirmYourIdentityAndSign IdentityTask -} - -// DonorProvidedDetails contains all the data related to the LPA application -type DonorProvidedDetails struct { - PK dynamo.LpaKeyType `hash:"-"` - SK dynamo.LpaOwnerKeyType `hash:"-"` - // Hash is used to determine whether the Lpa has been changed since last read - Hash uint64 `hash:"-"` - // HashVersion is used to determine the fields used to calculate Hash - HashVersion uint8 `hash:"-"` - // LpaID identifies the LPA being drafted - LpaID string - // LpaUID is a unique identifier created after sending basic LPA details to the UID service - LpaUID string `dynamodbav:",omitempty"` - // CreatedAt is when the LPA was created - CreatedAt time.Time - // UpdatedAt is when the LPA was last updated - UpdatedAt time.Time `hash:"-"` - // The donor the LPA relates to - Donor Donor - // Attorneys named in the LPA - Attorneys Attorneys - // Information on how the applicant wishes their attorneys to act - AttorneyDecisions AttorneyDecisions - // The certificate provider named in the LPA - CertificateProvider CertificateProvider - // Type of LPA being drafted - Type LpaType - // Whether the applicant wants to add replacement attorneys - WantReplacementAttorneys form.YesNo - // When the LPA can be used - WhenCanTheLpaBeUsed CanBeUsedWhen - // Preferences on life sustaining treatment (applicable to personal welfare LPAs only) - LifeSustainingTreatmentOption LifeSustainingTreatment - // Restrictions on attorneys actions - Restrictions string - // Used to show the task list - Tasks DonorTasks - // PaymentDetails are records of payments made for the LPA via GOV.UK Pay - PaymentDetails []Payment - // Information returned by the identity service related to the applicant - DonorIdentityUserData identity.UserData - // Replacement attorneys named in the LPA - ReplacementAttorneys Attorneys - // Information on how the applicant wishes their replacement attorneys to act - ReplacementAttorneyDecisions AttorneyDecisions - // How to bring in replacement attorneys, if set - HowShouldReplacementAttorneysStepIn ReplacementAttorneysStepIn - // Details on how replacement attorneys must step in if HowShouldReplacementAttorneysStepIn is set to "other" - HowShouldReplacementAttorneysStepInDetails string - // Whether the applicant wants to add a correspondent - AddCorrespondent form.YesNo - // Correspondent is sent updates on an application in place of a (supporter) donor - Correspondent Correspondent - // Whether the applicant wants to notify people about the application - DoYouWantToNotifyPeople form.YesNo - // People to notify about the application - PeopleToNotify PeopleToNotify - // The AuthorisedSignatory signs on the donor's behalf if they are unable to sign - AuthorisedSignatory AuthorisedSignatory - // The IndependentWitness acts as an additional witness when the LPA is signed - IndependentWitness IndependentWitness - // Confirmation that the applicant wants to apply to register the LPA - WantToApplyForLpa bool - // Confirmation that the applicant wants to sign the LPA - WantToSignLpa bool - // CertificateProviderNotRelatedConfirmedAt is when the donor confirmed the - // certificate provider is not related to another similar actor - CertificateProviderNotRelatedConfirmedAt time.Time - // CheckedAt is when the donor checked their LPA - CheckedAt time.Time - // CheckedHash is the Hash value of the LPA when last checked - CheckedHash uint64 `hash:"-"` - // CheckedHashVersion is used to determine the fields used to calculate CheckedHash - CheckedHashVersion uint8 `hash:"-"` - // SignedAt is when the donor submitted their signature - SignedAt time.Time - // SubmittedAt is when the Lpa was sent to the OPG - SubmittedAt time.Time - // WithdrawnAt is when the Lpa was withdrawn by the donor - WithdrawnAt time.Time - // PerfectAt is when the Lpa transitioned to the PERFECT status in the lpa-store - PerfectAt time.Time - // RegisteringWithCourtOfProtection is set when the donor wishes to take the - // Lpa to the Court of Protection for registration. - RegisteringWithCourtOfProtection bool - // Version is the number of times the LPA has been updated (auto-incremented - // on PUT) - Version int `hash:"-"` - - // WantVoucher indicates if the donor knows someone who can vouch for them and wants - // then to do so - WantVoucher form.YesNo - // Voucher is a person the donor has nominated to vouch for their identity - Voucher Voucher - - // Codes used for the certificate provider to witness signing - CertificateProviderCodes WitnessCodes - // When the signing was witnessed by the certificate provider - WitnessedByCertificateProviderAt time.Time - // Codes used for the independent witness to witness signing - IndependentWitnessCodes WitnessCodes - // When the signing was witnessed by the independent witness - WitnessedByIndependentWitnessAt time.Time - // Used to rate limit witness code attempts - WitnessCodeLimiter *Limiter - - // FeeType is the type of fee the user is applying for - FeeType pay.FeeType - // EvidenceDelivery is the method by which the user wants to send evidence - EvidenceDelivery pay.EvidenceDelivery - // PreviousApplicationNumber if the application is related to an existing application - PreviousApplicationNumber string - // PreviousFee is the fee previously paid for an LPA - PreviousFee pay.PreviousFee - - HasSentApplicationUpdatedEvent bool `hash:"-"` -} - -func (d *DonorProvidedDetails) HashInclude(field string, _ any) (bool, error) { - if d.HashVersion > currentHashVersion { - return false, errors.New("HashVersion too high") - } - - return true, nil -} - -// toCheck filters the fields used for hashing further, for the use of -// determining whether the LPA data has changed since it was checked by the -// donor. -type toCheck DonorProvidedDetails - -func (c toCheck) HashInclude(field string, _ any) (bool, error) { - if c.CheckedHashVersion > currentCheckedHashVersion { - return false, errors.New("CheckedHashVersion too high") - } - - // The following fields don't contain LPA data, so aren't part of what gets - // checked. - switch field { - case "CheckedAt", - "CreatedAt", - "Tasks", - "PaymentDetails", - "DonorIdentityUserData", - "WantToApplyForLpa", - "WantToSignLpa", - "SignedAt", - "SubmittedAt", - "WithdrawnAt", - "PerfectAt", - "CertificateProviderCodes", - "WitnessedByCertificateProviderAt", - "IndependentWitnessCodes", - "WitnessedByIndependentWitnessAt", - "WitnessCodeLimiter", - "FeeType", - "EvidenceDelivery", - "PreviousApplicationNumber", - "PreviousFee", - "RegisteringWithCourtOfProtection", - "WantVoucher", - "Voucher": - return false, nil - } - - return true, nil -} - -func (l *DonorProvidedDetails) NamesChanged(firstNames, lastName, otherNames string) bool { - return l.Donor.FirstNames != firstNames || l.Donor.LastName != lastName || l.Donor.OtherNames != otherNames -} - -func (l *DonorProvidedDetails) HashChanged() bool { - hash, _ := l.generateHash() - - return hash != l.Hash -} - -func (l *DonorProvidedDetails) UpdateHash() (err error) { - l.HashVersion = currentHashVersion - l.Hash, err = l.generateHash() - return err -} - -func (l *DonorProvidedDetails) generateHash() (uint64, error) { - return hashstructure.Hash(l, hashstructure.FormatV2, nil) -} - -func (l *DonorProvidedDetails) CheckedHashChanged() bool { - hash, _ := l.generateCheckedHash() - - return hash != l.CheckedHash -} - -func (l *DonorProvidedDetails) UpdateCheckedHash() (err error) { - l.CheckedHashVersion = currentCheckedHashVersion - l.CheckedHash, err = l.generateCheckedHash() - return err -} - -func (l *DonorProvidedDetails) generateCheckedHash() (uint64, error) { - return hashstructure.Hash(toCheck(*l), hashstructure.FormatV2, nil) -} - -func (l *DonorProvidedDetails) DonorIdentityConfirmed() bool { - return l.DonorIdentityUserData.Status.IsConfirmed() && - l.DonorIdentityUserData.MatchName(l.Donor.FirstNames, l.Donor.LastName) && - l.DonorIdentityUserData.DateOfBirth.Equals(l.Donor.DateOfBirth) -} - -func (l *DonorProvidedDetails) AttorneysAndCpSigningDeadline() time.Time { - return l.SignedAt.Add((24 * time.Hour) * 28) -} - -type Under18ActorDetails struct { - FullName string - DateOfBirth date.Date - UID actoruid.UID - Type Type -} - -func (l *DonorProvidedDetails) Under18ActorDetails() []Under18ActorDetails { - var data []Under18ActorDetails - eighteenYearsAgo := date.Today().AddDate(-18, 0, 0) - - for _, a := range l.Attorneys.Attorneys { - if a.DateOfBirth.After(eighteenYearsAgo) { - data = append(data, Under18ActorDetails{ - FullName: a.FullName(), - DateOfBirth: a.DateOfBirth, - UID: a.UID, - Type: TypeAttorney, - }) - } - } - - for _, ra := range l.ReplacementAttorneys.Attorneys { - if ra.DateOfBirth.After(eighteenYearsAgo) { - data = append(data, Under18ActorDetails{ - FullName: ra.FullName(), - DateOfBirth: ra.DateOfBirth, - UID: ra.UID, - Type: TypeReplacementAttorney, - }) - } - } - - return data -} - -func (l *DonorProvidedDetails) ActorAddresses() []place.Address { - var addresses []place.Address - - if l.Donor.Address.String() != "" { - addresses = append(addresses, l.Donor.Address) - } - - if l.CertificateProvider.Address.String() != "" && !slices.Contains(addresses, l.CertificateProvider.Address) { - addresses = append(addresses, l.CertificateProvider.Address) - } - - for _, address := range l.Attorneys.Addresses() { - if address.String() != "" && !slices.Contains(addresses, address) { - addresses = append(addresses, address) - } - } - - for _, address := range l.ReplacementAttorneys.Addresses() { - if address.String() != "" && !slices.Contains(addresses, address) { - addresses = append(addresses, address) - } - } - - return addresses -} - -func (l *DonorProvidedDetails) AllLayAttorneysFirstNames() []string { - var names []string - - for _, a := range l.Attorneys.Attorneys { - names = append(names, a.FirstNames) - } - - for _, a := range l.ReplacementAttorneys.Attorneys { - names = append(names, a.FirstNames) - } - - return names -} - -func (l *DonorProvidedDetails) AllLayAttorneysFullNames() []string { - var names []string - - for _, a := range l.Attorneys.Attorneys { - names = append(names, a.FullName()) - } - - for _, a := range l.ReplacementAttorneys.Attorneys { - names = append(names, a.FullName()) - } - - return names -} - -func (l *DonorProvidedDetails) TrustCorporationsNames() []string { - var names []string - - if l.Attorneys.TrustCorporation.Name != "" { - names = append(names, l.Attorneys.TrustCorporation.Name) - } - - if l.ReplacementAttorneys.TrustCorporation.Name != "" { - names = append(names, l.ReplacementAttorneys.TrustCorporation.Name) - } - - return names -} - -func (l *DonorProvidedDetails) Cost() int { - if l.Tasks.PayForLpa.IsDenied() { - return 8200 - } - - return pay.Cost(l.FeeType, l.PreviousFee) -} - -func (l *DonorProvidedDetails) FeeAmount() pay.AmountPence { - paid := 0 - - for _, payment := range l.PaymentDetails { - paid += payment.Amount - } - - return pay.AmountPence(l.Cost() - paid) -} - -// CertificateProviderSharesDetails will return true if the last name or address -// of the certificate provider matches that of the donor or one of the -// attorneys. For a match of the last name we break on '-' to account for -// double-barrelled names. -func (l *DonorProvidedDetails) CertificateProviderSharesDetails() bool { - certificateProviderParts := strings.Split(l.CertificateProvider.LastName, "-") - - donorParts := strings.Split(l.Donor.LastName, "-") - for _, certificateProviderPart := range certificateProviderParts { - if slices.Contains(donorParts, certificateProviderPart) { - return true - } - - if l.CertificateProvider.Address.Line1 == l.Donor.Address.Line1 && - l.CertificateProvider.Address.Postcode == l.Donor.Address.Postcode { - return true - } - } - - for _, attorney := range append(l.Attorneys.Attorneys, l.ReplacementAttorneys.Attorneys...) { - attorneyParts := strings.Split(attorney.LastName, "-") - - for _, certificateProviderPart := range certificateProviderParts { - if slices.Contains(attorneyParts, certificateProviderPart) { - return true - } +type DonorTasks = donordata.DonorTasks - if l.CertificateProvider.Address.Line1 == attorney.Address.Line1 && - l.CertificateProvider.Address.Postcode == attorney.Address.Postcode { - return true - } - } - } +type DonorProvidedDetails = donordata.DonorProvidedDetails - return false -} +type Under18ActorDetails = donordata.Under18ActorDetails diff --git a/internal/actor/enum_novoucherdecision.go b/internal/actor/enum_novoucherdecision.go index 8fc5e626be..a7162174f2 100644 --- a/internal/actor/enum_novoucherdecision.go +++ b/internal/actor/enum_novoucherdecision.go @@ -21,9 +21,6 @@ const _NoVoucherDecision_name = "prove-own-idselect-new-voucherwithdraw-lpaapply var _NoVoucherDecision_index = [...]uint8{0, 12, 30, 42, 54} func (i NoVoucherDecision) String() string { - if i == 0 { - return "" - } i -= 1 if i >= NoVoucherDecision(len(_NoVoucherDecision_index)-1) { return "NoVoucherDecision(" + strconv.FormatInt(int64(i+1), 10) + ")" diff --git a/internal/actor/life_sustaining_treatment.go b/internal/actor/life_sustaining_treatment.go index 5d148834e1..43185beab5 100644 --- a/internal/actor/life_sustaining_treatment.go +++ b/internal/actor/life_sustaining_treatment.go @@ -1,9 +1,10 @@ package actor -//go:generate enumerator -type LifeSustainingTreatment -linecomment -trimprefix -empty -type LifeSustainingTreatment uint8 +import "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" + +type LifeSustainingTreatment = donordata.LifeSustainingTreatment const ( - LifeSustainingTreatmentOptionA LifeSustainingTreatment = iota + 1 // option-a - LifeSustainingTreatmentOptionB // option-b + LifeSustainingTreatmentOptionA = donordata.LifeSustainingTreatmentOptionA + LifeSustainingTreatmentOptionB = donordata.LifeSustainingTreatmentOptionB ) diff --git a/internal/actor/limiter.go b/internal/actor/limiter.go index cd357cec57..4050961f91 100644 --- a/internal/actor/limiter.go +++ b/internal/actor/limiter.go @@ -1,45 +1,7 @@ package actor -import ( - "sync" - "time" -) +import "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" -// Limiter is a basic rate limiter that can be serialised. -type Limiter struct { - TokenPer time.Duration - MaxTokens float64 +type Limiter = donordata.Limiter - mu sync.Mutex - Tokens float64 - TokensAt time.Time -} - -func NewLimiter(tokenPer time.Duration, initialTokens, maxTokens float64) *Limiter { - return &Limiter{ - TokenPer: tokenPer, - MaxTokens: maxTokens, - Tokens: initialTokens, - TokensAt: time.Now(), - } -} - -func (l *Limiter) Allow(now time.Time) bool { - l.mu.Lock() - defer l.mu.Unlock() - - elapsed := now.Sub(l.TokensAt) - l.Tokens += elapsed.Seconds() / l.TokenPer.Seconds() - l.TokensAt = now - - if l.Tokens > l.MaxTokens { - l.Tokens = l.MaxTokens - } - - if l.Tokens >= 1 { - l.Tokens-- - return true - } - - return false -} +var NewLimiter = donordata.NewLimiter diff --git a/internal/actor/lpa_type.go b/internal/actor/lpa_type.go index 11cb6eb2a1..a1fa23e6f7 100644 --- a/internal/actor/lpa_type.go +++ b/internal/actor/lpa_type.go @@ -1,19 +1,10 @@ package actor -//go:generate enumerator -type LpaType -linecomment -trimprefix -empty -type LpaType uint8 +import "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" + +type LpaType = donordata.LpaType const ( - LpaTypePersonalWelfare LpaType = iota + 1 // personal-welfare - LpaTypePropertyAndAffairs // property-and-affairs + LpaTypePersonalWelfare = donordata.LpaTypePersonalWelfare + LpaTypePropertyAndAffairs = donordata.LpaTypePropertyAndAffairs ) - -func (e LpaType) WhatLPACoversTransKey() string { - switch e { - case LpaTypePropertyAndAffairs: - return "whatPropertyAndAffairsCovers" - case LpaTypePersonalWelfare: - return "whatPersonalWelfareCovers" - } - return "" -} diff --git a/internal/actor/payment.go b/internal/actor/payment.go index 2974832567..ab4d7b90e7 100644 --- a/internal/actor/payment.go +++ b/internal/actor/payment.go @@ -1,10 +1,5 @@ package actor -type Payment struct { - // Reference generated for the payment - PaymentReference string - // ID returned from GOV.UK Pay - PaymentId string - // Amount is the amount paid in pence - Amount int -} +import "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" + +type Payment = donordata.Payment diff --git a/internal/actor/person_to_notify.go b/internal/actor/person_to_notify.go index 7bef29c702..c74fb1d62f 100644 --- a/internal/actor/person_to_notify.go +++ b/internal/actor/person_to_notify.go @@ -1,55 +1,8 @@ package actor import ( - "slices" - - "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" - "github.com/ministryofjustice/opg-modernising-lpa/internal/place" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" ) -// PersonToNotify contains details about a person to notify, provided by the applicant -type PersonToNotify struct { - UID actoruid.UID - // First names of the person to notify - FirstNames string - // Last name of the person to notify - LastName string - // Address of the person to notify - Address place.Address -} - -func (p PersonToNotify) FullName() string { - return p.FirstNames + " " + p.LastName -} - -type PeopleToNotify []PersonToNotify - -func (ps PeopleToNotify) Get(uid actoruid.UID) (PersonToNotify, bool) { - idx := slices.IndexFunc(ps, func(p PersonToNotify) bool { return p.UID == uid }) - if idx == -1 { - return PersonToNotify{}, false - } - - return ps[idx], true -} - -func (ps PeopleToNotify) Put(person PersonToNotify) bool { - idx := slices.IndexFunc(ps, func(p PersonToNotify) bool { return p.UID == person.UID }) - if idx == -1 { - return false - } - - ps[idx] = person - return true -} - -func (ps *PeopleToNotify) Delete(personToNotify PersonToNotify) bool { - idx := slices.IndexFunc(*ps, func(p PersonToNotify) bool { return p.UID == personToNotify.UID }) - if idx == -1 { - return false - } - - *ps = slices.Delete(*ps, idx, idx+1) - - return true -} +type PersonToNotify = donordata.PersonToNotify +type PeopleToNotify = donordata.PeopleToNotify diff --git a/internal/actor/replacement_attorneys_step_in.go b/internal/actor/replacement_attorneys_step_in.go index da860820e2..1040e65e56 100644 --- a/internal/actor/replacement_attorneys_step_in.go +++ b/internal/actor/replacement_attorneys_step_in.go @@ -1,10 +1,11 @@ package actor -//go:generate enumerator -type ReplacementAttorneysStepIn -linecomment -trimprefix -empty -type ReplacementAttorneysStepIn uint8 +import "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" + +type ReplacementAttorneysStepIn = donordata.ReplacementAttorneysStepIn const ( - ReplacementAttorneysStepInWhenAllCanNoLongerAct ReplacementAttorneysStepIn = iota + 1 // all-can-no-longer-act - ReplacementAttorneysStepInWhenOneCanNoLongerAct // one-can-no-longer-act - ReplacementAttorneysStepInAnotherWay // another-way + ReplacementAttorneysStepInWhenAllCanNoLongerAct = donordata.ReplacementAttorneysStepInWhenAllCanNoLongerAct + ReplacementAttorneysStepInWhenOneCanNoLongerAct = donordata.ReplacementAttorneysStepInWhenOneCanNoLongerAct + ReplacementAttorneysStepInAnotherWay = donordata.ReplacementAttorneysStepInAnotherWay ) diff --git a/internal/actor/task_state_test.go b/internal/actor/task_state_test.go deleted file mode 100644 index d18a2f0a77..0000000000 --- a/internal/actor/task_state_test.go +++ /dev/null @@ -1,33 +0,0 @@ -package actor - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestTaskStateString(t *testing.T) { - testCases := []struct { - State TaskState - Expected string - }{ - { - State: TaskNotStarted, - Expected: "notStarted", - }, - { - State: TaskInProgress, - Expected: "inProgress", - }, - { - State: TaskCompleted, - Expected: "completed", - }, - } - - for _, tc := range testCases { - t.Run(tc.Expected, func(t *testing.T) { - assert.Equal(t, tc.Expected, tc.State.String()) - }) - } -} diff --git a/internal/actor/voucher.go b/internal/actor/voucher.go index 897cd66b23..21a00adda2 100644 --- a/internal/actor/voucher.go +++ b/internal/actor/voucher.go @@ -1,56 +1,5 @@ package actor -import "strings" +import "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" -type Voucher struct { - FirstNames string - LastName string - Email string - Allowed bool -} - -func (v Voucher) FullName() string { - return v.FirstNames + " " + v.LastName -} - -func (v Voucher) Matches(donor *DonorProvidedDetails) (match []Type) { - if v.FirstNames == "" && v.LastName == "" { - return nil - } - - if strings.EqualFold(donor.Donor.FirstNames, v.FirstNames) && strings.EqualFold(donor.Donor.LastName, v.LastName) { - match = append(match, TypeDonor) - } - - for _, attorney := range donor.Attorneys.Attorneys { - if strings.EqualFold(attorney.FirstNames, v.FirstNames) && strings.EqualFold(attorney.LastName, v.LastName) { - match = append(match, TypeAttorney) - } - } - - for _, attorney := range donor.ReplacementAttorneys.Attorneys { - if strings.EqualFold(attorney.FirstNames, v.FirstNames) && strings.EqualFold(attorney.LastName, v.LastName) { - match = append(match, TypeReplacementAttorney) - } - } - - if strings.EqualFold(donor.CertificateProvider.FirstNames, v.FirstNames) && strings.EqualFold(donor.CertificateProvider.LastName, v.LastName) { - match = append(match, TypeCertificateProvider) - } - - for _, person := range donor.PeopleToNotify { - if strings.EqualFold(person.FirstNames, v.FirstNames) && strings.EqualFold(person.LastName, v.LastName) { - match = append(match, TypePersonToNotify) - } - } - - if strings.EqualFold(donor.AuthorisedSignatory.FirstNames, v.FirstNames) && strings.EqualFold(donor.AuthorisedSignatory.LastName, v.LastName) { - match = append(match, TypeAuthorisedSignatory) - } - - if strings.EqualFold(donor.IndependentWitness.FirstNames, v.FirstNames) && strings.EqualFold(donor.IndependentWitness.LastName, v.LastName) { - match = append(match, TypeIndependentWitness) - } - - return match -} +type Voucher = donordata.Voucher diff --git a/internal/actor/witness_codes.go b/internal/actor/witness_codes.go index e62de4385b..8fb693201f 100644 --- a/internal/actor/witness_codes.go +++ b/internal/actor/witness_codes.go @@ -1,43 +1,8 @@ package actor -import "time" - -const ( - witnessCodeExpireAfter = 15 * time.Minute - witnessCodeIgnoreAfter = 2 * time.Hour - witnessCodeRequestAfter = time.Minute +import ( + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" ) -type WitnessCode struct { - Code string - Created time.Time -} - -func (w WitnessCode) HasExpired() bool { - return w.Created.Add(witnessCodeExpireAfter).Before(time.Now()) -} - -type WitnessCodes []WitnessCode - -func (ws WitnessCodes) Find(code string) (WitnessCode, bool) { - for _, w := range ws { - if w.Code == code { - if w.Created.Add(witnessCodeIgnoreAfter).Before(time.Now()) { - break - } - - return w, true - } - } - - return WitnessCode{}, false -} - -func (ws WitnessCodes) CanRequest(now time.Time) bool { - if len(ws) == 0 { - return true - } - - lastCode := ws[len(ws)-1] - return lastCode.Created.Add(witnessCodeRequestAfter).Before(now) -} +type WitnessCode = donordata.WitnessCode +type WitnessCodes = donordata.WitnessCodes diff --git a/internal/actor/yes_no_maybe.go b/internal/actor/yes_no_maybe.go index 78d0aafe60..5f6517ad45 100644 --- a/internal/actor/yes_no_maybe.go +++ b/internal/actor/yes_no_maybe.go @@ -1,10 +1,11 @@ package actor -//go:generate enumerator -type YesNoMaybe -linecomment -empty -type YesNoMaybe uint8 +import "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" + +type YesNoMaybe = donordata.YesNoMaybe const ( - Yes YesNoMaybe = iota + 1 - No - Maybe + Yes = donordata.Yes + No = donordata.No + Maybe = donordata.Maybe ) diff --git a/internal/donor/donordata/attorney.go b/internal/donor/donordata/attorney.go new file mode 100644 index 0000000000..7e93b49991 --- /dev/null +++ b/internal/donor/donordata/attorney.go @@ -0,0 +1,37 @@ +package donordata + +import ( + "fmt" + + "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 +} diff --git a/internal/donor/donordata/attorney_decisions.go b/internal/donor/donordata/attorney_decisions.go new file mode 100644 index 0000000000..4a7c259310 --- /dev/null +++ b/internal/donor/donordata/attorney_decisions.go @@ -0,0 +1,49 @@ +package donordata + +//go:generate enumerator -type AttorneysAct -linecomment -empty +type AttorneysAct uint8 + +const ( + // Jointly indicates attorneys or replacement attorneys should act jointly + Jointly AttorneysAct = iota + 1 // jointly + + // JointlyAndSeverally indicates attorneys or replacement attorneys should act + // jointly and severally + JointlyAndSeverally // jointly-and-severally + + // JointlyForSomeSeverallyForOthers indicates attorneys or replacement + // attorneys should act jointly for some decisions, and jointly and severally + // for other decisions + JointlyForSomeSeverallyForOthers // jointly-for-some-severally-for-others +) + +// AttorneyDecisions contains details about how an attorney or replacement attorney should act, provided by the applicant +type AttorneyDecisions struct { + // How attorneys should make decisions + How AttorneysAct + // Details on how attorneys should make decisions if acting jointly for some decisions, and jointly and severally for other decisions + Details string +} + +func MakeAttorneyDecisions(existing AttorneyDecisions, how AttorneysAct, details string) AttorneyDecisions { + if existing.How == how { + if how == JointlyForSomeSeverallyForOthers { + existing.Details = details + } + + return existing + } + + if how != JointlyForSomeSeverallyForOthers { + return AttorneyDecisions{How: how} + } + + return AttorneyDecisions{ + How: how, + Details: details, + } +} + +func (d AttorneyDecisions) IsComplete() bool { + return !d.How.Empty() +} diff --git a/internal/actor/attorney_decisions_test.go b/internal/donor/donordata/attorney_decisions_test.go similarity index 98% rename from internal/actor/attorney_decisions_test.go rename to internal/donor/donordata/attorney_decisions_test.go index 011f7afdb1..e2eb36d138 100644 --- a/internal/actor/attorney_decisions_test.go +++ b/internal/donor/donordata/attorney_decisions_test.go @@ -1,4 +1,4 @@ -package actor +package donordata import ( "testing" diff --git a/internal/actor/attorney_test.go b/internal/donor/donordata/attorney_test.go similarity index 99% rename from internal/actor/attorney_test.go rename to internal/donor/donordata/attorney_test.go index 9121a0d8f1..4c8c03fb57 100644 --- a/internal/actor/attorney_test.go +++ b/internal/donor/donordata/attorney_test.go @@ -1,4 +1,4 @@ -package actor +package donordata import ( "testing" diff --git a/internal/donor/donordata/attorneys.go b/internal/donor/donordata/attorneys.go new file mode 100644 index 0000000000..64e617377c --- /dev/null +++ b/internal/donor/donordata/attorneys.go @@ -0,0 +1,112 @@ +package donordata + +import ( + "fmt" + "slices" + + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/place" +) + +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 == "" { + 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 +} diff --git a/internal/donor/donordata/authorised_signatory.go b/internal/donor/donordata/authorised_signatory.go new file mode 100644 index 0000000000..4aef694c6d --- /dev/null +++ b/internal/donor/donordata/authorised_signatory.go @@ -0,0 +1,13 @@ +package donordata + +import "fmt" + +// AuthorisedSignatory contains details of the person who will sign the LPA on the donor's behalf +type AuthorisedSignatory struct { + FirstNames string + LastName string +} + +func (s AuthorisedSignatory) FullName() string { + return fmt.Sprintf("%s %s", s.FirstNames, s.LastName) +} diff --git a/internal/donor/donordata/can_be_used_when.go b/internal/donor/donordata/can_be_used_when.go new file mode 100644 index 0000000000..7bf6ed9de7 --- /dev/null +++ b/internal/donor/donordata/can_be_used_when.go @@ -0,0 +1,10 @@ +package donordata + +//go:generate enumerator -type CanBeUsedWhen -linecomment -trimprefix +type CanBeUsedWhen uint8 + +const ( + CanBeUsedWhenUnknown CanBeUsedWhen = iota + CanBeUsedWhenCapacityLost // when-capacity-lost + CanBeUsedWhenHasCapacity // when-has-capacity +) diff --git a/internal/actor/can_be_used_when_test.go b/internal/donor/donordata/can_be_used_when_test.go similarity index 97% rename from internal/actor/can_be_used_when_test.go rename to internal/donor/donordata/can_be_used_when_test.go index dbaf0aec53..1689e2f471 100644 --- a/internal/actor/can_be_used_when_test.go +++ b/internal/donor/donordata/can_be_used_when_test.go @@ -1,4 +1,4 @@ -package actor +package donordata import ( "fmt" diff --git a/internal/donor/donordata/certificate_provider.go b/internal/donor/donordata/certificate_provider.go new file mode 100644 index 0000000000..7cbbff1bb4 --- /dev/null +++ b/internal/donor/donordata/certificate_provider.go @@ -0,0 +1,53 @@ +package donordata + +import ( + "fmt" + + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/place" +) + +//go:generate enumerator -type CertificateProviderRelationship -linecomment -empty +type CertificateProviderRelationship uint8 + +const ( + Personally CertificateProviderRelationship = iota + 1 // personally + Professionally // professionally +) + +//go:generate enumerator -type CertificateProviderRelationshipLength -linecomment +type CertificateProviderRelationshipLength uint8 + +const ( + RelationshipLengthUnknown CertificateProviderRelationshipLength = iota // unknown + LessThanTwoYears // lt-2-years + GreaterThanEqualToTwoYears // gte-2-years +) + +// CertificateProvider contains details about the certificate provider, provided by the applicant +type CertificateProvider struct { + // UID for the actor + UID actoruid.UID + // First names of the certificate provider + FirstNames string + // Last name of the certificate provider + LastName string + // Address of the certificate provider + Address place.Address + // Mobile number of the certificate provider, used to send witness codes + Mobile string + // HasNonUKMobile indicates whether the value of Mobile is a non-UK mobile number + HasNonUKMobile bool + // Email of the certificate provider + Email string + // How the certificate provider wants to perform their role (paper or online) + CarryOutBy Channel + // The certificate provider's relationship to the applicant + Relationship CertificateProviderRelationship + // Amount of time Relationship has been in place if Personally + RelationshipLength CertificateProviderRelationshipLength +} + +func (c CertificateProvider) FullName() string { + return fmt.Sprintf("%s %s", c.FirstNames, c.LastName) +} diff --git a/internal/actor/certificate_provider_test.go b/internal/donor/donordata/certificate_provider_test.go similarity index 92% rename from internal/actor/certificate_provider_test.go rename to internal/donor/donordata/certificate_provider_test.go index 6aa70da44f..151b5c33f3 100644 --- a/internal/actor/certificate_provider_test.go +++ b/internal/donor/donordata/certificate_provider_test.go @@ -1,4 +1,4 @@ -package actor +package donordata import ( "testing" diff --git a/internal/donor/donordata/channel.go b/internal/donor/donordata/channel.go new file mode 100644 index 0000000000..1d9861b9cf --- /dev/null +++ b/internal/donor/donordata/channel.go @@ -0,0 +1,9 @@ +package donordata + +//go:generate enumerator -type Channel -linecomment -empty -trimprefix +type Channel uint8 + +const ( + ChannelPaper Channel = iota + 1 // paper + ChannelOnline // online +) diff --git a/internal/donor/donordata/correspondent.go b/internal/donor/donordata/correspondent.go new file mode 100644 index 0000000000..fe6c66c004 --- /dev/null +++ b/internal/donor/donordata/correspondent.go @@ -0,0 +1,29 @@ +package donordata + +import ( + "github.com/ministryofjustice/opg-modernising-lpa/internal/form" + "github.com/ministryofjustice/opg-modernising-lpa/internal/place" +) + +//go:generate enumerator -type CorrespondentShare -linecomment -trimprefix -empty -bits +type CorrespondentShare uint8 + +const ( + CorrespondentShareAttorneys CorrespondentShare = 2 << iota + CorrespondentShareCertificateProvider +) + +type Correspondent struct { + FirstNames string + LastName string + Email string + Organisation string + Telephone string + WantAddress form.YesNo + Address place.Address + Share CorrespondentShare +} + +func (c Correspondent) FullName() string { + return c.FirstNames + " " + c.LastName +} diff --git a/internal/actor/correspondent_test.go b/internal/donor/donordata/correspondent_test.go similarity index 92% rename from internal/actor/correspondent_test.go rename to internal/donor/donordata/correspondent_test.go index ab88c2ed12..d4548b9d48 100644 --- a/internal/actor/correspondent_test.go +++ b/internal/donor/donordata/correspondent_test.go @@ -1,4 +1,4 @@ -package actor +package donordata import ( "testing" diff --git a/internal/donor/donordata/donor.go b/internal/donor/donordata/donor.go new file mode 100644 index 0000000000..f24dbf51ab --- /dev/null +++ b/internal/donor/donordata/donor.go @@ -0,0 +1,44 @@ +package donordata + +import ( + "fmt" + "strings" + + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/date" + "github.com/ministryofjustice/opg-modernising-lpa/internal/form" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" + "github.com/ministryofjustice/opg-modernising-lpa/internal/place" +) + +// Donor contains details about the donor, provided by the applicant +type Donor struct { + // UID for the actor + UID actoruid.UID + // First names of the donor + FirstNames string + // Last name of the donor + LastName string + // Email of the donor + Email string + // Other names the donor is known by + OtherNames string + // Date of birth of the donor + DateOfBirth date.Date + // Address of the donor + Address place.Address + // ThinksCanSign is what the donor thinks about their ability to sign online + ThinksCanSign YesNoMaybe + // CanSign is Yes if the donor has said they will sign online + CanSign form.YesNo + // Channel is how the Donor is applying for their LPA (paper or online) + Channel Channel + // ContactLanguagePreference is the language the donor prefers to receive notifications in + ContactLanguagePreference localize.Lang + // LpaLanguagePreference is the language the donor prefers to receive the registered LPA in + LpaLanguagePreference localize.Lang +} + +func (d Donor) FullName() string { + return strings.Trim(fmt.Sprintf("%s %s", d.FirstNames, d.LastName), " ") +} diff --git a/internal/actor/donor_provided_test.go b/internal/donor/donordata/donor_provided_test.go similarity index 97% rename from internal/actor/donor_provided_test.go rename to internal/donor/donordata/donor_provided_test.go index 43eb4deaa9..1b8e0636d7 100644 --- a/internal/actor/donor_provided_test.go +++ b/internal/donor/donordata/donor_provided_test.go @@ -1,4 +1,4 @@ -package actor +package donordata import ( "fmt" @@ -9,6 +9,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" + "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" "github.com/stretchr/testify/assert" ) @@ -238,8 +239,8 @@ func TestUnder18ActorDetails(t *testing.T) { actors := donor.Under18ActorDetails() assert.Equal(t, []Under18ActorDetails{ - {FullName: "a b", DateOfBirth: under18, UID: uid1, Type: TypeAttorney}, - {FullName: "e f", DateOfBirth: under18, UID: uid3, Type: TypeReplacementAttorney}, + {FullName: "a b", DateOfBirth: under18, UID: uid1, Type: temporary.ActorTypeAttorney}, + {FullName: "e f", DateOfBirth: under18, UID: uid3, Type: temporary.ActorTypeReplacementAttorney}, }, actors) } diff --git a/internal/actor/donor_test.go b/internal/donor/donordata/donor_test.go similarity index 97% rename from internal/actor/donor_test.go rename to internal/donor/donordata/donor_test.go index e873ae1fb0..78277cf81f 100644 --- a/internal/actor/donor_test.go +++ b/internal/donor/donordata/donor_test.go @@ -1,4 +1,4 @@ -package actor +package donordata import ( "testing" diff --git a/internal/actor/enum_attorneysact.go b/internal/donor/donordata/enum_attorneysact.go similarity index 98% rename from internal/actor/enum_attorneysact.go rename to internal/donor/donordata/enum_attorneysact.go index 9f4039cb84..17cca921a5 100644 --- a/internal/actor/enum_attorneysact.go +++ b/internal/donor/donordata/enum_attorneysact.go @@ -1,5 +1,5 @@ // Code generated by "enumerator -type AttorneysAct -linecomment -empty"; DO NOT EDIT. -package actor +package donordata import ( "fmt" @@ -20,9 +20,6 @@ const _AttorneysAct_name = "jointlyjointly-and-severallyjointly-for-some-several var _AttorneysAct_index = [...]uint8{0, 7, 28, 65} func (i AttorneysAct) String() string { - if i == 0 { - return "" - } i -= 1 if i >= AttorneysAct(len(_AttorneysAct_index)-1) { return "AttorneysAct(" + strconv.FormatInt(int64(i+1), 10) + ")" diff --git a/internal/actor/enum_canbeusedwhen.go b/internal/donor/donordata/enum_canbeusedwhen.go similarity index 99% rename from internal/actor/enum_canbeusedwhen.go rename to internal/donor/donordata/enum_canbeusedwhen.go index b20db1bfa8..f11cdae503 100644 --- a/internal/actor/enum_canbeusedwhen.go +++ b/internal/donor/donordata/enum_canbeusedwhen.go @@ -1,5 +1,5 @@ // Code generated by "enumerator -type CanBeUsedWhen -linecomment -trimprefix"; DO NOT EDIT. -package actor +package donordata import ( "fmt" diff --git a/internal/actor/enum_certificateproviderrelationship.go b/internal/donor/donordata/enum_certificateproviderrelationship.go similarity index 98% rename from internal/actor/enum_certificateproviderrelationship.go rename to internal/donor/donordata/enum_certificateproviderrelationship.go index ca686cb839..aadfeb76cf 100644 --- a/internal/actor/enum_certificateproviderrelationship.go +++ b/internal/donor/donordata/enum_certificateproviderrelationship.go @@ -1,5 +1,5 @@ // Code generated by "enumerator -type CertificateProviderRelationship -linecomment -empty"; DO NOT EDIT. -package actor +package donordata import ( "fmt" @@ -19,9 +19,6 @@ const _CertificateProviderRelationship_name = "personallyprofessionally" var _CertificateProviderRelationship_index = [...]uint8{0, 10, 24} func (i CertificateProviderRelationship) String() string { - if i == 0 { - return "" - } i -= 1 if i >= CertificateProviderRelationship(len(_CertificateProviderRelationship_index)-1) { return "CertificateProviderRelationship(" + strconv.FormatInt(int64(i+1), 10) + ")" diff --git a/internal/actor/enum_certificateproviderrelationshiplength.go b/internal/donor/donordata/enum_certificateproviderrelationshiplength.go similarity index 99% rename from internal/actor/enum_certificateproviderrelationshiplength.go rename to internal/donor/donordata/enum_certificateproviderrelationshiplength.go index 9e81049312..00eca5db26 100644 --- a/internal/actor/enum_certificateproviderrelationshiplength.go +++ b/internal/donor/donordata/enum_certificateproviderrelationshiplength.go @@ -1,5 +1,5 @@ // Code generated by "enumerator -type CertificateProviderRelationshipLength -linecomment"; DO NOT EDIT. -package actor +package donordata import ( "fmt" diff --git a/internal/actor/enum_channel.go b/internal/donor/donordata/enum_channel.go similarity index 97% rename from internal/actor/enum_channel.go rename to internal/donor/donordata/enum_channel.go index 814fbfc26d..85a6c08248 100644 --- a/internal/actor/enum_channel.go +++ b/internal/donor/donordata/enum_channel.go @@ -1,5 +1,5 @@ // Code generated by "enumerator -type Channel -linecomment -empty -trimprefix"; DO NOT EDIT. -package actor +package donordata import ( "fmt" @@ -19,9 +19,6 @@ const _Channel_name = "paperonline" var _Channel_index = [...]uint8{0, 5, 11} func (i Channel) String() string { - if i == 0 { - return "" - } i -= 1 if i >= Channel(len(_Channel_index)-1) { return "Channel(" + strconv.FormatInt(int64(i+1), 10) + ")" diff --git a/internal/actor/enum_correspondentshare.go b/internal/donor/donordata/enum_correspondentshare.go similarity index 99% rename from internal/actor/enum_correspondentshare.go rename to internal/donor/donordata/enum_correspondentshare.go index fde53f643a..1452a8b524 100644 --- a/internal/actor/enum_correspondentshare.go +++ b/internal/donor/donordata/enum_correspondentshare.go @@ -1,5 +1,5 @@ // Code generated by "enumerator -type CorrespondentShare -linecomment -trimprefix -empty -bits"; DO NOT EDIT. -package actor +package donordata import ( "fmt" diff --git a/internal/actor/enum_lifesustainingtreatment.go b/internal/donor/donordata/enum_lifesustainingtreatment.go similarity index 97% rename from internal/actor/enum_lifesustainingtreatment.go rename to internal/donor/donordata/enum_lifesustainingtreatment.go index dc79bd6c69..7618c4527b 100644 --- a/internal/actor/enum_lifesustainingtreatment.go +++ b/internal/donor/donordata/enum_lifesustainingtreatment.go @@ -1,5 +1,5 @@ // Code generated by "enumerator -type LifeSustainingTreatment -linecomment -trimprefix -empty"; DO NOT EDIT. -package actor +package donordata import ( "fmt" @@ -19,9 +19,6 @@ const _LifeSustainingTreatment_name = "option-aoption-b" var _LifeSustainingTreatment_index = [...]uint8{0, 8, 16} func (i LifeSustainingTreatment) String() string { - if i == 0 { - return "" - } i -= 1 if i >= LifeSustainingTreatment(len(_LifeSustainingTreatment_index)-1) { return "LifeSustainingTreatment(" + strconv.FormatInt(int64(i+1), 10) + ")" diff --git a/internal/actor/enum_lpatype.go b/internal/donor/donordata/enum_lpatype.go similarity index 97% rename from internal/actor/enum_lpatype.go rename to internal/donor/donordata/enum_lpatype.go index b244ef3d0e..03d17f8bb3 100644 --- a/internal/actor/enum_lpatype.go +++ b/internal/donor/donordata/enum_lpatype.go @@ -1,5 +1,5 @@ // Code generated by "enumerator -type LpaType -linecomment -trimprefix -empty"; DO NOT EDIT. -package actor +package donordata import ( "fmt" @@ -19,9 +19,6 @@ const _LpaType_name = "personal-welfareproperty-and-affairs" var _LpaType_index = [...]uint8{0, 16, 36} func (i LpaType) String() string { - if i == 0 { - return "" - } i -= 1 if i >= LpaType(len(_LpaType_index)-1) { return "LpaType(" + strconv.FormatInt(int64(i+1), 10) + ")" diff --git a/internal/actor/enum_replacementattorneysstepin.go b/internal/donor/donordata/enum_replacementattorneysstepin.go similarity index 98% rename from internal/actor/enum_replacementattorneysstepin.go rename to internal/donor/donordata/enum_replacementattorneysstepin.go index a5a98d8e21..090da5fe5f 100644 --- a/internal/actor/enum_replacementattorneysstepin.go +++ b/internal/donor/donordata/enum_replacementattorneysstepin.go @@ -1,5 +1,5 @@ // Code generated by "enumerator -type ReplacementAttorneysStepIn -linecomment -trimprefix -empty"; DO NOT EDIT. -package actor +package donordata import ( "fmt" @@ -20,9 +20,6 @@ const _ReplacementAttorneysStepIn_name = "all-can-no-longer-actone-can-no-longer var _ReplacementAttorneysStepIn_index = [...]uint8{0, 21, 42, 53} func (i ReplacementAttorneysStepIn) String() string { - if i == 0 { - return "" - } i -= 1 if i >= ReplacementAttorneysStepIn(len(_ReplacementAttorneysStepIn_index)-1) { return "ReplacementAttorneysStepIn(" + strconv.FormatInt(int64(i+1), 10) + ")" diff --git a/internal/actor/enum_yesnomaybe.go b/internal/donor/donordata/enum_yesnomaybe.go similarity index 97% rename from internal/actor/enum_yesnomaybe.go rename to internal/donor/donordata/enum_yesnomaybe.go index 873d42d79e..7e1333f8f3 100644 --- a/internal/actor/enum_yesnomaybe.go +++ b/internal/donor/donordata/enum_yesnomaybe.go @@ -1,5 +1,5 @@ // Code generated by "enumerator -type YesNoMaybe -linecomment -empty"; DO NOT EDIT. -package actor +package donordata import ( "fmt" @@ -20,9 +20,6 @@ const _YesNoMaybe_name = "YesNoMaybe" var _YesNoMaybe_index = [...]uint8{0, 3, 5, 10} func (i YesNoMaybe) String() string { - if i == 0 { - return "" - } i -= 1 if i >= YesNoMaybe(len(_YesNoMaybe_index)-1) { return "YesNoMaybe(" + strconv.FormatInt(int64(i+1), 10) + ")" diff --git a/internal/donor/donordata/independent_witness.go b/internal/donor/donordata/independent_witness.go new file mode 100644 index 0000000000..651839353f --- /dev/null +++ b/internal/donor/donordata/independent_witness.go @@ -0,0 +1,20 @@ +package donordata + +import ( + "fmt" + + "github.com/ministryofjustice/opg-modernising-lpa/internal/place" +) + +// IndependentWitness contains details of the person who will also witness the signing of the LPA +type IndependentWitness struct { + FirstNames string + LastName string + HasNonUKMobile bool + Mobile string + Address place.Address +} + +func (w IndependentWitness) FullName() string { + return fmt.Sprintf("%s %s", w.FirstNames, w.LastName) +} diff --git a/internal/donor/donordata/life_sustaining_treatment.go b/internal/donor/donordata/life_sustaining_treatment.go new file mode 100644 index 0000000000..96a408ffcf --- /dev/null +++ b/internal/donor/donordata/life_sustaining_treatment.go @@ -0,0 +1,9 @@ +package donordata + +//go:generate enumerator -type LifeSustainingTreatment -linecomment -trimprefix -empty +type LifeSustainingTreatment uint8 + +const ( + LifeSustainingTreatmentOptionA LifeSustainingTreatment = iota + 1 // option-a + LifeSustainingTreatmentOptionB // option-b +) diff --git a/internal/actor/life_sustaining_treatment_test.go b/internal/donor/donordata/life_sustaining_treatment_test.go similarity index 98% rename from internal/actor/life_sustaining_treatment_test.go rename to internal/donor/donordata/life_sustaining_treatment_test.go index d24c688d08..7e7dcdfe54 100644 --- a/internal/actor/life_sustaining_treatment_test.go +++ b/internal/donor/donordata/life_sustaining_treatment_test.go @@ -1,4 +1,4 @@ -package actor +package donordata import ( "fmt" diff --git a/internal/donor/donordata/limiter.go b/internal/donor/donordata/limiter.go new file mode 100644 index 0000000000..c199626b3c --- /dev/null +++ b/internal/donor/donordata/limiter.go @@ -0,0 +1,45 @@ +package donordata + +import ( + "sync" + "time" +) + +// Limiter is a basic rate limiter that can be serialised. +type Limiter struct { + TokenPer time.Duration + MaxTokens float64 + + mu sync.Mutex + Tokens float64 + TokensAt time.Time +} + +func NewLimiter(tokenPer time.Duration, initialTokens, maxTokens float64) *Limiter { + return &Limiter{ + TokenPer: tokenPer, + MaxTokens: maxTokens, + Tokens: initialTokens, + TokensAt: time.Now(), + } +} + +func (l *Limiter) Allow(now time.Time) bool { + l.mu.Lock() + defer l.mu.Unlock() + + elapsed := now.Sub(l.TokensAt) + l.Tokens += elapsed.Seconds() / l.TokenPer.Seconds() + l.TokensAt = now + + if l.Tokens > l.MaxTokens { + l.Tokens = l.MaxTokens + } + + if l.Tokens >= 1 { + l.Tokens-- + return true + } + + return false +} diff --git a/internal/actor/limiter_test.go b/internal/donor/donordata/limiter_test.go similarity index 99% rename from internal/actor/limiter_test.go rename to internal/donor/donordata/limiter_test.go index 27230ae12c..95a682a694 100644 --- a/internal/actor/limiter_test.go +++ b/internal/donor/donordata/limiter_test.go @@ -1,4 +1,4 @@ -package actor +package donordata import ( "testing" diff --git a/internal/donor/donordata/lpa_type.go b/internal/donor/donordata/lpa_type.go new file mode 100644 index 0000000000..67b92630f8 --- /dev/null +++ b/internal/donor/donordata/lpa_type.go @@ -0,0 +1,19 @@ +package donordata + +//go:generate enumerator -type LpaType -linecomment -trimprefix -empty +type LpaType uint8 + +const ( + LpaTypePersonalWelfare LpaType = iota + 1 // personal-welfare + LpaTypePropertyAndAffairs // property-and-affairs +) + +func (e LpaType) WhatLPACoversTransKey() string { + switch e { + case LpaTypePropertyAndAffairs: + return "whatPropertyAndAffairsCovers" + case LpaTypePersonalWelfare: + return "whatPersonalWelfareCovers" + } + return "" +} diff --git a/internal/actor/lpa_type_test.go b/internal/donor/donordata/lpa_type_test.go similarity index 98% rename from internal/actor/lpa_type_test.go rename to internal/donor/donordata/lpa_type_test.go index ce18365a18..e59fe009ea 100644 --- a/internal/actor/lpa_type_test.go +++ b/internal/donor/donordata/lpa_type_test.go @@ -1,4 +1,4 @@ -package actor +package donordata import ( "fmt" diff --git a/internal/actor/mock_Localizer_test.go b/internal/donor/donordata/mock_Localizer_test.go similarity index 99% rename from internal/actor/mock_Localizer_test.go rename to internal/donor/donordata/mock_Localizer_test.go index e554870f9b..e17a79522d 100644 --- a/internal/actor/mock_Localizer_test.go +++ b/internal/donor/donordata/mock_Localizer_test.go @@ -1,6 +1,6 @@ // Code generated by mockery v2.42.0. DO NOT EDIT. -package actor +package donordata import mock "github.com/stretchr/testify/mock" diff --git a/internal/donor/donordata/payment.go b/internal/donor/donordata/payment.go new file mode 100644 index 0000000000..425b844993 --- /dev/null +++ b/internal/donor/donordata/payment.go @@ -0,0 +1,10 @@ +package donordata + +type Payment struct { + // Reference generated for the payment + PaymentReference string + // ID returned from GOV.UK Pay + PaymentId string + // Amount is the amount paid in pence + Amount int +} diff --git a/internal/donor/donordata/people_to_notify.go b/internal/donor/donordata/people_to_notify.go new file mode 100644 index 0000000000..10b14b95fd --- /dev/null +++ b/internal/donor/donordata/people_to_notify.go @@ -0,0 +1,39 @@ +package donordata + +import ( + "slices" + + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" +) + +type PeopleToNotify []PersonToNotify + +func (ps PeopleToNotify) Get(uid actoruid.UID) (PersonToNotify, bool) { + idx := slices.IndexFunc(ps, func(p PersonToNotify) bool { return p.UID == uid }) + if idx == -1 { + return PersonToNotify{}, false + } + + return ps[idx], true +} + +func (ps PeopleToNotify) Put(person PersonToNotify) bool { + idx := slices.IndexFunc(ps, func(p PersonToNotify) bool { return p.UID == person.UID }) + if idx == -1 { + return false + } + + ps[idx] = person + return true +} + +func (ps *PeopleToNotify) Delete(personToNotify PersonToNotify) bool { + idx := slices.IndexFunc(*ps, func(p PersonToNotify) bool { return p.UID == personToNotify.UID }) + if idx == -1 { + return false + } + + *ps = slices.Delete(*ps, idx, idx+1) + + return true +} diff --git a/internal/donor/donordata/person_to_notify.go b/internal/donor/donordata/person_to_notify.go new file mode 100644 index 0000000000..2e707cc98d --- /dev/null +++ b/internal/donor/donordata/person_to_notify.go @@ -0,0 +1,21 @@ +package donordata + +import ( + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/place" +) + +// PersonToNotify contains details about a person to notify, provided by the applicant +type PersonToNotify struct { + UID actoruid.UID + // First names of the person to notify + FirstNames string + // Last name of the person to notify + LastName string + // Address of the person to notify + Address place.Address +} + +func (p PersonToNotify) FullName() string { + return p.FirstNames + " " + p.LastName +} diff --git a/internal/actor/person_to_notify_test.go b/internal/donor/donordata/person_to_notify_test.go similarity index 99% rename from internal/actor/person_to_notify_test.go rename to internal/donor/donordata/person_to_notify_test.go index c0f6301529..f3edaf3814 100644 --- a/internal/actor/person_to_notify_test.go +++ b/internal/donor/donordata/person_to_notify_test.go @@ -1,4 +1,4 @@ -package actor +package donordata import ( "testing" diff --git a/internal/donor/donordata/provided.go b/internal/donor/donordata/provided.go new file mode 100644 index 0000000000..f9e03fae77 --- /dev/null +++ b/internal/donor/donordata/provided.go @@ -0,0 +1,412 @@ +package donordata + +import ( + "errors" + "slices" + "strings" + "time" + + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/date" + "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" + "github.com/ministryofjustice/opg-modernising-lpa/internal/form" + "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" + "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" + "github.com/ministryofjustice/opg-modernising-lpa/internal/place" + "github.com/ministryofjustice/opg-modernising-lpa/internal/task" + "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" + "github.com/mitchellh/hashstructure/v2" +) + +const ( + currentHashVersion uint8 = 0 + currentCheckedHashVersion uint8 = 0 +) + +type DonorTasks struct { + YourDetails task.State + ChooseAttorneys task.State + ChooseReplacementAttorneys task.State + WhenCanTheLpaBeUsed task.State // property and affairs only + LifeSustainingTreatment task.State // personal welfare only + Restrictions task.State + CertificateProvider task.State + PeopleToNotify task.State + AddCorrespondent task.State + ChooseYourSignatory task.State // if .Donor.CanSign.IsNo only + CheckYourLpa task.State + PayForLpa task.PaymentState + ConfirmYourIdentityAndSign task.IdentityState +} + +// DonorProvidedDetails contains all the data related to the LPA application +type DonorProvidedDetails struct { + PK dynamo.LpaKeyType `hash:"-"` + SK dynamo.LpaOwnerKeyType `hash:"-"` + // Hash is used to determine whether the Lpa has been changed since last read + Hash uint64 `hash:"-"` + // HashVersion is used to determine the fields used to calculate Hash + HashVersion uint8 `hash:"-"` + // LpaID identifies the LPA being drafted + LpaID string + // LpaUID is a unique identifier created after sending basic LPA details to the UID service + LpaUID string `dynamodbav:",omitempty"` + // CreatedAt is when the LPA was created + CreatedAt time.Time + // UpdatedAt is when the LPA was last updated + UpdatedAt time.Time `hash:"-"` + // The donor the LPA relates to + Donor Donor + // Attorneys named in the LPA + Attorneys Attorneys + // Information on how the applicant wishes their attorneys to act + AttorneyDecisions AttorneyDecisions + // The certificate provider named in the LPA + CertificateProvider CertificateProvider + // Type of LPA being drafted + Type LpaType + // Whether the applicant wants to add replacement attorneys + WantReplacementAttorneys form.YesNo + // When the LPA can be used + WhenCanTheLpaBeUsed CanBeUsedWhen + // Preferences on life sustaining treatment (applicable to personal welfare LPAs only) + LifeSustainingTreatmentOption LifeSustainingTreatment + // Restrictions on attorneys actions + Restrictions string + // Used to show the task list + Tasks DonorTasks + // PaymentDetails are records of payments made for the LPA via GOV.UK Pay + PaymentDetails []Payment + // Information returned by the identity service related to the applicant + DonorIdentityUserData identity.UserData + // Replacement attorneys named in the LPA + ReplacementAttorneys Attorneys + // Information on how the applicant wishes their replacement attorneys to act + ReplacementAttorneyDecisions AttorneyDecisions + // How to bring in replacement attorneys, if set + HowShouldReplacementAttorneysStepIn ReplacementAttorneysStepIn + // Details on how replacement attorneys must step in if HowShouldReplacementAttorneysStepIn is set to "other" + HowShouldReplacementAttorneysStepInDetails string + // Whether the applicant wants to add a correspondent + AddCorrespondent form.YesNo + // Correspondent is sent updates on an application in place of a (supporter) donor + Correspondent Correspondent + // Whether the applicant wants to notify people about the application + DoYouWantToNotifyPeople form.YesNo + // People to notify about the application + PeopleToNotify PeopleToNotify + // The AuthorisedSignatory signs on the donor's behalf if they are unable to sign + AuthorisedSignatory AuthorisedSignatory + // The IndependentWitness acts as an additional witness when the LPA is signed + IndependentWitness IndependentWitness + // Confirmation that the applicant wants to apply to register the LPA + WantToApplyForLpa bool + // Confirmation that the applicant wants to sign the LPA + WantToSignLpa bool + // CertificateProviderNotRelatedConfirmedAt is when the donor confirmed the + // certificate provider is not related to another similar actor + CertificateProviderNotRelatedConfirmedAt time.Time + // CheckedAt is when the donor checked their LPA + CheckedAt time.Time + // CheckedHash is the Hash value of the LPA when last checked + CheckedHash uint64 `hash:"-"` + // CheckedHashVersion is used to determine the fields used to calculate CheckedHash + CheckedHashVersion uint8 `hash:"-"` + // SignedAt is when the donor submitted their signature + SignedAt time.Time + // SubmittedAt is when the Lpa was sent to the OPG + SubmittedAt time.Time + // WithdrawnAt is when the Lpa was withdrawn by the donor + WithdrawnAt time.Time + // PerfectAt is when the Lpa transitioned to the PERFECT status in the lpa-store + PerfectAt time.Time + // RegisteringWithCourtOfProtection is set when the donor wishes to take the + // Lpa to the Court of Protection for registration. + RegisteringWithCourtOfProtection bool + // Version is the number of times the LPA has been updated (auto-incremented + // on PUT) + Version int `hash:"-"` + + // WantVoucher indicates if the donor knows someone who can vouch for them and wants + // then to do so + WantVoucher form.YesNo + // Voucher is a person the donor has nominated to vouch for their identity + Voucher Voucher + + // Codes used for the certificate provider to witness signing + CertificateProviderCodes WitnessCodes + // When the signing was witnessed by the certificate provider + WitnessedByCertificateProviderAt time.Time + // Codes used for the independent witness to witness signing + IndependentWitnessCodes WitnessCodes + // When the signing was witnessed by the independent witness + WitnessedByIndependentWitnessAt time.Time + // Used to rate limit witness code attempts + WitnessCodeLimiter *Limiter + + // FeeType is the type of fee the user is applying for + FeeType pay.FeeType + // EvidenceDelivery is the method by which the user wants to send evidence + EvidenceDelivery pay.EvidenceDelivery + // PreviousApplicationNumber if the application is related to an existing application + PreviousApplicationNumber string + // PreviousFee is the fee previously paid for an LPA + PreviousFee pay.PreviousFee + + HasSentApplicationUpdatedEvent bool `hash:"-"` +} + +func (d *DonorProvidedDetails) HashInclude(field string, _ any) (bool, error) { + if d.HashVersion > currentHashVersion { + return false, errors.New("HashVersion too high") + } + + return true, nil +} + +// toCheck filters the fields used for hashing further, for the use of +// determining whether the LPA data has changed since it was checked by the +// donor. +type toCheck DonorProvidedDetails + +func (c toCheck) HashInclude(field string, _ any) (bool, error) { + if c.CheckedHashVersion > currentCheckedHashVersion { + return false, errors.New("CheckedHashVersion too high") + } + + // The following fields don't contain LPA data, so aren't part of what gets + // checked. + switch field { + case "CheckedAt", + "CreatedAt", + "Tasks", + "PaymentDetails", + "DonorIdentityUserData", + "WantToApplyForLpa", + "WantToSignLpa", + "SignedAt", + "SubmittedAt", + "WithdrawnAt", + "PerfectAt", + "CertificateProviderCodes", + "WitnessedByCertificateProviderAt", + "IndependentWitnessCodes", + "WitnessedByIndependentWitnessAt", + "WitnessCodeLimiter", + "FeeType", + "EvidenceDelivery", + "PreviousApplicationNumber", + "PreviousFee", + "RegisteringWithCourtOfProtection", + "WantVoucher", + "Voucher": + return false, nil + } + + return true, nil +} + +func (l *DonorProvidedDetails) NamesChanged(firstNames, lastName, otherNames string) bool { + return l.Donor.FirstNames != firstNames || l.Donor.LastName != lastName || l.Donor.OtherNames != otherNames +} + +func (l *DonorProvidedDetails) HashChanged() bool { + hash, _ := l.generateHash() + + return hash != l.Hash +} + +func (l *DonorProvidedDetails) UpdateHash() (err error) { + l.HashVersion = currentHashVersion + l.Hash, err = l.generateHash() + return err +} + +func (l *DonorProvidedDetails) generateHash() (uint64, error) { + return hashstructure.Hash(l, hashstructure.FormatV2, nil) +} + +func (l *DonorProvidedDetails) CheckedHashChanged() bool { + hash, _ := l.generateCheckedHash() + + return hash != l.CheckedHash +} + +func (l *DonorProvidedDetails) UpdateCheckedHash() (err error) { + l.CheckedHashVersion = currentCheckedHashVersion + l.CheckedHash, err = l.generateCheckedHash() + return err +} + +func (l *DonorProvidedDetails) generateCheckedHash() (uint64, error) { + return hashstructure.Hash(toCheck(*l), hashstructure.FormatV2, nil) +} + +func (l *DonorProvidedDetails) DonorIdentityConfirmed() bool { + return l.DonorIdentityUserData.Status.IsConfirmed() && + l.DonorIdentityUserData.MatchName(l.Donor.FirstNames, l.Donor.LastName) && + l.DonorIdentityUserData.DateOfBirth.Equals(l.Donor.DateOfBirth) +} + +func (l *DonorProvidedDetails) AttorneysAndCpSigningDeadline() time.Time { + return l.SignedAt.Add((24 * time.Hour) * 28) +} + +type Under18ActorDetails struct { + FullName string + DateOfBirth date.Date + UID actoruid.UID + Type temporary.ActorType +} + +func (l *DonorProvidedDetails) Under18ActorDetails() []Under18ActorDetails { + var data []Under18ActorDetails + eighteenYearsAgo := date.Today().AddDate(-18, 0, 0) + + for _, a := range l.Attorneys.Attorneys { + if a.DateOfBirth.After(eighteenYearsAgo) { + data = append(data, Under18ActorDetails{ + FullName: a.FullName(), + DateOfBirth: a.DateOfBirth, + UID: a.UID, + Type: temporary.ActorTypeAttorney, + }) + } + } + + for _, ra := range l.ReplacementAttorneys.Attorneys { + if ra.DateOfBirth.After(eighteenYearsAgo) { + data = append(data, Under18ActorDetails{ + FullName: ra.FullName(), + DateOfBirth: ra.DateOfBirth, + UID: ra.UID, + Type: temporary.ActorTypeReplacementAttorney, + }) + } + } + + return data +} + +func (l *DonorProvidedDetails) ActorAddresses() []place.Address { + var addresses []place.Address + + if l.Donor.Address.String() != "" { + addresses = append(addresses, l.Donor.Address) + } + + if l.CertificateProvider.Address.String() != "" && !slices.Contains(addresses, l.CertificateProvider.Address) { + addresses = append(addresses, l.CertificateProvider.Address) + } + + for _, address := range l.Attorneys.Addresses() { + if address.String() != "" && !slices.Contains(addresses, address) { + addresses = append(addresses, address) + } + } + + for _, address := range l.ReplacementAttorneys.Addresses() { + if address.String() != "" && !slices.Contains(addresses, address) { + addresses = append(addresses, address) + } + } + + return addresses +} + +func (l *DonorProvidedDetails) AllLayAttorneysFirstNames() []string { + var names []string + + for _, a := range l.Attorneys.Attorneys { + names = append(names, a.FirstNames) + } + + for _, a := range l.ReplacementAttorneys.Attorneys { + names = append(names, a.FirstNames) + } + + return names +} + +func (l *DonorProvidedDetails) AllLayAttorneysFullNames() []string { + var names []string + + for _, a := range l.Attorneys.Attorneys { + names = append(names, a.FullName()) + } + + for _, a := range l.ReplacementAttorneys.Attorneys { + names = append(names, a.FullName()) + } + + return names +} + +func (l *DonorProvidedDetails) TrustCorporationsNames() []string { + var names []string + + if l.Attorneys.TrustCorporation.Name != "" { + names = append(names, l.Attorneys.TrustCorporation.Name) + } + + if l.ReplacementAttorneys.TrustCorporation.Name != "" { + names = append(names, l.ReplacementAttorneys.TrustCorporation.Name) + } + + return names +} + +func (l *DonorProvidedDetails) Cost() int { + if l.Tasks.PayForLpa.IsDenied() { + return 8200 + } + + return pay.Cost(l.FeeType, l.PreviousFee) +} + +func (l *DonorProvidedDetails) FeeAmount() pay.AmountPence { + paid := 0 + + for _, payment := range l.PaymentDetails { + paid += payment.Amount + } + + return pay.AmountPence(l.Cost() - paid) +} + +// CertificateProviderSharesDetails will return true if the last name or address +// of the certificate provider matches that of the donor or one of the +// attorneys. For a match of the last name we break on '-' to account for +// double-barrelled names. +func (l *DonorProvidedDetails) CertificateProviderSharesDetails() bool { + certificateProviderParts := strings.Split(l.CertificateProvider.LastName, "-") + + donorParts := strings.Split(l.Donor.LastName, "-") + for _, certificateProviderPart := range certificateProviderParts { + if slices.Contains(donorParts, certificateProviderPart) { + return true + } + + if l.CertificateProvider.Address.Line1 == l.Donor.Address.Line1 && + l.CertificateProvider.Address.Postcode == l.Donor.Address.Postcode { + return true + } + } + + for _, attorney := range append(l.Attorneys.Attorneys, l.ReplacementAttorneys.Attorneys...) { + attorneyParts := strings.Split(attorney.LastName, "-") + + for _, certificateProviderPart := range certificateProviderParts { + if slices.Contains(attorneyParts, certificateProviderPart) { + return true + } + + if l.CertificateProvider.Address.Line1 == attorney.Address.Line1 && + l.CertificateProvider.Address.Postcode == attorney.Address.Postcode { + return true + } + } + } + + return false +} diff --git a/internal/donor/donordata/replacement_attorneys_step_in.go b/internal/donor/donordata/replacement_attorneys_step_in.go new file mode 100644 index 0000000000..7d30ff8372 --- /dev/null +++ b/internal/donor/donordata/replacement_attorneys_step_in.go @@ -0,0 +1,10 @@ +package donordata + +//go:generate enumerator -type ReplacementAttorneysStepIn -linecomment -trimprefix -empty +type ReplacementAttorneysStepIn uint8 + +const ( + ReplacementAttorneysStepInWhenAllCanNoLongerAct ReplacementAttorneysStepIn = iota + 1 // all-can-no-longer-act + ReplacementAttorneysStepInWhenOneCanNoLongerAct // one-can-no-longer-act + ReplacementAttorneysStepInAnotherWay // another-way +) diff --git a/internal/actor/replacement_attorneys_step_in_test.go b/internal/donor/donordata/replacement_attorneys_step_in_test.go similarity index 98% rename from internal/actor/replacement_attorneys_step_in_test.go rename to internal/donor/donordata/replacement_attorneys_step_in_test.go index ab5549c9e0..cd187d2b28 100644 --- a/internal/actor/replacement_attorneys_step_in_test.go +++ b/internal/donor/donordata/replacement_attorneys_step_in_test.go @@ -1,4 +1,4 @@ -package actor +package donordata import ( "fmt" diff --git a/internal/donor/donordata/trust_corporation.go b/internal/donor/donordata/trust_corporation.go new file mode 100644 index 0000000000..66b0379db7 --- /dev/null +++ b/internal/donor/donordata/trust_corporation.go @@ -0,0 +1,28 @@ +package donordata + +import ( + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/place" +) + +// 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 +} diff --git a/internal/donor/donordata/voucher.go b/internal/donor/donordata/voucher.go new file mode 100644 index 0000000000..9e1f11f1ff --- /dev/null +++ b/internal/donor/donordata/voucher.go @@ -0,0 +1,60 @@ +package donordata + +import ( + "strings" + + "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" +) + +type Voucher struct { + FirstNames string + LastName string + Email string + Allowed bool +} + +func (v Voucher) FullName() string { + return v.FirstNames + " " + v.LastName +} + +func (v Voucher) Matches(donor *DonorProvidedDetails) (match []temporary.ActorType) { + if v.FirstNames == "" && v.LastName == "" { + return nil + } + + if strings.EqualFold(donor.Donor.FirstNames, v.FirstNames) && strings.EqualFold(donor.Donor.LastName, v.LastName) { + match = append(match, temporary.ActorTypeDonor) + } + + for _, attorney := range donor.Attorneys.Attorneys { + if strings.EqualFold(attorney.FirstNames, v.FirstNames) && strings.EqualFold(attorney.LastName, v.LastName) { + match = append(match, temporary.ActorTypeAttorney) + } + } + + for _, attorney := range donor.ReplacementAttorneys.Attorneys { + if strings.EqualFold(attorney.FirstNames, v.FirstNames) && strings.EqualFold(attorney.LastName, v.LastName) { + match = append(match, temporary.ActorTypeReplacementAttorney) + } + } + + if strings.EqualFold(donor.CertificateProvider.FirstNames, v.FirstNames) && strings.EqualFold(donor.CertificateProvider.LastName, v.LastName) { + match = append(match, temporary.ActorTypeCertificateProvider) + } + + for _, person := range donor.PeopleToNotify { + if strings.EqualFold(person.FirstNames, v.FirstNames) && strings.EqualFold(person.LastName, v.LastName) { + match = append(match, temporary.ActorTypePersonToNotify) + } + } + + if strings.EqualFold(donor.AuthorisedSignatory.FirstNames, v.FirstNames) && strings.EqualFold(donor.AuthorisedSignatory.LastName, v.LastName) { + match = append(match, temporary.ActorTypeAuthorisedSignatory) + } + + if strings.EqualFold(donor.IndependentWitness.FirstNames, v.FirstNames) && strings.EqualFold(donor.IndependentWitness.LastName, v.LastName) { + match = append(match, temporary.ActorTypeIndependentWitness) + } + + return match +} diff --git a/internal/actor/voucher_test.go b/internal/donor/donordata/voucher_test.go similarity index 56% rename from internal/actor/voucher_test.go rename to internal/donor/donordata/voucher_test.go index 1977211295..aabe413fe9 100644 --- a/internal/actor/voucher_test.go +++ b/internal/donor/donordata/voucher_test.go @@ -1,8 +1,9 @@ -package actor +package donordata import ( "testing" + "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" "github.com/stretchr/testify/assert" ) @@ -31,16 +32,16 @@ func TestVoucherMatches(t *testing.T) { } assert.Nil(t, Voucher{FirstNames: "x", LastName: "y"}.Matches(donor)) - assert.Equal(t, []Type{TypeDonor}, Voucher{FirstNames: "a", LastName: "b"}.Matches(donor)) - assert.Equal(t, []Type{TypeAttorney}, Voucher{FirstNames: "C", LastName: "D"}.Matches(donor)) - assert.Equal(t, []Type{TypeAttorney}, Voucher{FirstNames: "e", LastName: "f"}.Matches(donor)) - assert.Equal(t, []Type{TypeReplacementAttorney}, Voucher{FirstNames: "G", LastName: "H"}.Matches(donor)) - assert.Equal(t, []Type{TypeReplacementAttorney}, Voucher{FirstNames: "i", LastName: "j"}.Matches(donor)) - assert.Equal(t, []Type{TypeCertificateProvider}, Voucher{FirstNames: "k", LastName: "l"}.Matches(donor)) - assert.Equal(t, []Type{TypePersonToNotify}, Voucher{FirstNames: "m", LastName: "n"}.Matches(donor)) - assert.Equal(t, []Type{TypePersonToNotify}, Voucher{FirstNames: "O", LastName: "P"}.Matches(donor)) - assert.Equal(t, []Type{TypeAuthorisedSignatory}, Voucher{FirstNames: "a", LastName: "s"}.Matches(donor)) - assert.Equal(t, []Type{TypeIndependentWitness}, Voucher{FirstNames: "i", LastName: "w"}.Matches(donor)) + assert.Equal(t, []temporary.ActorType{temporary.ActorTypeDonor}, Voucher{FirstNames: "a", LastName: "b"}.Matches(donor)) + assert.Equal(t, []temporary.ActorType{temporary.ActorTypeAttorney}, Voucher{FirstNames: "C", LastName: "D"}.Matches(donor)) + assert.Equal(t, []temporary.ActorType{temporary.ActorTypeAttorney}, Voucher{FirstNames: "e", LastName: "f"}.Matches(donor)) + assert.Equal(t, []temporary.ActorType{temporary.ActorTypeReplacementAttorney}, Voucher{FirstNames: "G", LastName: "H"}.Matches(donor)) + assert.Equal(t, []temporary.ActorType{temporary.ActorTypeReplacementAttorney}, Voucher{FirstNames: "i", LastName: "j"}.Matches(donor)) + assert.Equal(t, []temporary.ActorType{temporary.ActorTypeCertificateProvider}, Voucher{FirstNames: "k", LastName: "l"}.Matches(donor)) + assert.Equal(t, []temporary.ActorType{temporary.ActorTypePersonToNotify}, Voucher{FirstNames: "m", LastName: "n"}.Matches(donor)) + assert.Equal(t, []temporary.ActorType{temporary.ActorTypePersonToNotify}, Voucher{FirstNames: "O", LastName: "P"}.Matches(donor)) + assert.Equal(t, []temporary.ActorType{temporary.ActorTypeAuthorisedSignatory}, Voucher{FirstNames: "a", LastName: "s"}.Matches(donor)) + assert.Equal(t, []temporary.ActorType{temporary.ActorTypeIndependentWitness}, Voucher{FirstNames: "i", LastName: "w"}.Matches(donor)) } func TestVoucherMatchesMultiple(t *testing.T) { @@ -63,8 +64,8 @@ func TestVoucherMatchesMultiple(t *testing.T) { IndependentWitness: IndependentWitness{FirstNames: "a", LastName: "b"}, } - assert.Equal(t, []Type{TypeDonor, TypeAttorney, TypeAttorney, TypeReplacementAttorney, TypeReplacementAttorney, - TypeCertificateProvider, TypePersonToNotify, TypePersonToNotify, TypeAuthorisedSignatory, TypeIndependentWitness}, + assert.Equal(t, []temporary.ActorType{temporary.ActorTypeDonor, temporary.ActorTypeAttorney, temporary.ActorTypeAttorney, temporary.ActorTypeReplacementAttorney, temporary.ActorTypeReplacementAttorney, + temporary.ActorTypeCertificateProvider, temporary.ActorTypePersonToNotify, temporary.ActorTypePersonToNotify, temporary.ActorTypeAuthorisedSignatory, temporary.ActorTypeIndependentWitness}, Voucher{FirstNames: "a", LastName: "b"}.Matches(donor)) } diff --git a/internal/donor/donordata/witness_codes.go b/internal/donor/donordata/witness_codes.go new file mode 100644 index 0000000000..7e1c36b9f6 --- /dev/null +++ b/internal/donor/donordata/witness_codes.go @@ -0,0 +1,43 @@ +package donordata + +import "time" + +const ( + witnessCodeExpireAfter = 15 * time.Minute + witnessCodeIgnoreAfter = 2 * time.Hour + witnessCodeRequestAfter = time.Minute +) + +type WitnessCode struct { + Code string + Created time.Time +} + +func (w WitnessCode) HasExpired() bool { + return w.Created.Add(witnessCodeExpireAfter).Before(time.Now()) +} + +type WitnessCodes []WitnessCode + +func (ws WitnessCodes) Find(code string) (WitnessCode, bool) { + for _, w := range ws { + if w.Code == code { + if w.Created.Add(witnessCodeIgnoreAfter).Before(time.Now()) { + break + } + + return w, true + } + } + + return WitnessCode{}, false +} + +func (ws WitnessCodes) CanRequest(now time.Time) bool { + if len(ws) == 0 { + return true + } + + lastCode := ws[len(ws)-1] + return lastCode.Created.Add(witnessCodeRequestAfter).Before(now) +} diff --git a/internal/actor/witness_codes_test.go b/internal/donor/donordata/witness_codes_test.go similarity index 99% rename from internal/actor/witness_codes_test.go rename to internal/donor/donordata/witness_codes_test.go index f4e28c66d4..de07971549 100644 --- a/internal/actor/witness_codes_test.go +++ b/internal/donor/donordata/witness_codes_test.go @@ -1,4 +1,4 @@ -package actor +package donordata import ( "testing" diff --git a/internal/donor/donordata/yes_no_maybe.go b/internal/donor/donordata/yes_no_maybe.go new file mode 100644 index 0000000000..19df42b8b7 --- /dev/null +++ b/internal/donor/donordata/yes_no_maybe.go @@ -0,0 +1,10 @@ +package donordata + +//go:generate enumerator -type YesNoMaybe -linecomment -empty +type YesNoMaybe uint8 + +const ( + Yes YesNoMaybe = iota + 1 + No + Maybe +) diff --git a/internal/localize/enum_lang.go b/internal/localize/enum_lang.go index 82fcb84961..63cfdfa278 100644 --- a/internal/localize/enum_lang.go +++ b/internal/localize/enum_lang.go @@ -19,9 +19,6 @@ const _Lang_name = "ency" var _Lang_index = [...]uint8{0, 2, 4} func (i Lang) String() string { - if i == 0 { - return "" - } i -= 1 if i >= Lang(len(_Lang_index)-1) { return "Lang(" + strconv.FormatInt(int64(i+1), 10) + ")" diff --git a/internal/page/donor/can_you_sign_your_lpa.go b/internal/page/donor/can_you_sign_your_lpa.go index e5fafff6e9..0d9df68b96 100644 --- a/internal/page/donor/can_you_sign_your_lpa.go +++ b/internal/page/donor/can_you_sign_your_lpa.go @@ -5,6 +5,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" @@ -14,7 +15,7 @@ type canYouSignYourLpaData struct { App page.AppData Errors validation.List Form *canYouSignYourLpaForm - YesNoMaybeOptions actor.YesNoMaybeOptions + YesNoMaybeOptions donordata.YesNoMaybeOptions CanTaskList bool } @@ -25,7 +26,7 @@ func CanYouSignYourLpa(tmpl template.Template, donorStore DonorStore) Handler { Form: &canYouSignYourLpaForm{ CanSign: donor.Donor.ThinksCanSign, }, - YesNoMaybeOptions: actor.YesNoMaybeValues, + YesNoMaybeOptions: donordata.YesNoMaybeValues, CanTaskList: !donor.Type.Empty(), } @@ -62,7 +63,7 @@ type canYouSignYourLpaForm struct { } func readYourDetailsForm(r *http.Request) *canYouSignYourLpaForm { - canSign, canSignError := actor.ParseYesNoMaybe(page.PostFormString(r, "can-sign")) + canSign, canSignError := donordata.ParseYesNoMaybe(page.PostFormString(r, "can-sign")) return &canYouSignYourLpaForm{ CanSign: canSign, diff --git a/internal/page/donor/can_you_sign_your_lpa_test.go b/internal/page/donor/can_you_sign_your_lpa_test.go index 2deddc40fd..82d5d4037a 100644 --- a/internal/page/donor/can_you_sign_your_lpa_test.go +++ b/internal/page/donor/can_you_sign_your_lpa_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" @@ -24,7 +25,7 @@ func TestGetCanYouSignYourLpa(t *testing.T) { On("Execute", w, &canYouSignYourLpaData{ App: testAppData, Form: &canYouSignYourLpaForm{}, - YesNoMaybeOptions: actor.YesNoMaybeValues, + YesNoMaybeOptions: donordata.YesNoMaybeValues, }). Return(nil) diff --git a/internal/page/donor/how_do_you_know_your_certificate_provider.go b/internal/page/donor/how_do_you_know_your_certificate_provider.go index 3b0a94c572..7574427650 100644 --- a/internal/page/donor/how_do_you_know_your_certificate_provider.go +++ b/internal/page/donor/how_do_you_know_your_certificate_provider.go @@ -5,6 +5,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" @@ -15,7 +16,7 @@ type howDoYouKnowYourCertificateProviderData struct { Errors validation.List CertificateProvider actor.CertificateProvider Form *howDoYouKnowYourCertificateProviderForm - Options actor.CertificateProviderRelationshipOptions + Options donordata.CertificateProviderRelationshipOptions } func HowDoYouKnowYourCertificateProvider(tmpl template.Template, donorStore DonorStore) Handler { @@ -26,7 +27,7 @@ func HowDoYouKnowYourCertificateProvider(tmpl template.Template, donorStore Dono Form: &howDoYouKnowYourCertificateProviderForm{ How: donor.CertificateProvider.Relationship, }, - Options: actor.CertificateProviderRelationshipValues, + Options: donordata.CertificateProviderRelationshipValues, } if r.Method == http.MethodPost { @@ -67,7 +68,7 @@ type howDoYouKnowYourCertificateProviderForm struct { } func readHowDoYouKnowYourCertificateProviderForm(r *http.Request) *howDoYouKnowYourCertificateProviderForm { - how, err := actor.ParseCertificateProviderRelationship(page.PostFormString(r, "how")) + how, err := donordata.ParseCertificateProviderRelationship(page.PostFormString(r, "how")) return &howDoYouKnowYourCertificateProviderForm{ How: how, diff --git a/internal/page/donor/how_do_you_know_your_certificate_provider_test.go b/internal/page/donor/how_do_you_know_your_certificate_provider_test.go index a77b5d5c53..9ed76a36e0 100644 --- a/internal/page/donor/how_do_you_know_your_certificate_provider_test.go +++ b/internal/page/donor/how_do_you_know_your_certificate_provider_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" @@ -24,7 +25,7 @@ func TestGetHowDoYouKnowYourCertificateProvider(t *testing.T) { Execute(w, &howDoYouKnowYourCertificateProviderData{ App: testAppData, Form: &howDoYouKnowYourCertificateProviderForm{}, - Options: actor.CertificateProviderRelationshipValues, + Options: donordata.CertificateProviderRelationshipValues, }). Return(nil) @@ -49,7 +50,7 @@ func TestGetHowDoYouKnowYourCertificateProviderFromStore(t *testing.T) { App: testAppData, CertificateProvider: certificateProvider, Form: &howDoYouKnowYourCertificateProviderForm{How: actor.Personally}, - Options: actor.CertificateProviderRelationshipValues, + Options: donordata.CertificateProviderRelationshipValues, }). Return(nil) diff --git a/internal/page/donor/how_long_have_you_known_certificate_provider.go b/internal/page/donor/how_long_have_you_known_certificate_provider.go index f985f9ffac..f4fba7dba6 100644 --- a/internal/page/donor/how_long_have_you_known_certificate_provider.go +++ b/internal/page/donor/how_long_have_you_known_certificate_provider.go @@ -5,6 +5,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) @@ -14,7 +15,7 @@ type howLongHaveYouKnownCertificateProviderData struct { Errors validation.List CertificateProvider actor.CertificateProvider RelationshipLength actor.CertificateProviderRelationshipLength - Options actor.CertificateProviderRelationshipLengthOptions + Options donordata.CertificateProviderRelationshipLengthOptions } func HowLongHaveYouKnownCertificateProvider(tmpl template.Template, donorStore DonorStore) Handler { @@ -23,7 +24,7 @@ func HowLongHaveYouKnownCertificateProvider(tmpl template.Template, donorStore D App: appData, CertificateProvider: donor.CertificateProvider, RelationshipLength: donor.CertificateProvider.RelationshipLength, - Options: actor.CertificateProviderRelationshipLengthValues, + Options: donordata.CertificateProviderRelationshipLengthValues, } if r.Method == http.MethodPost { @@ -54,7 +55,7 @@ type howLongHaveYouKnownCertificateProviderForm struct { } func readHowLongHaveYouKnownCertificateProviderForm(r *http.Request) *howLongHaveYouKnownCertificateProviderForm { - relationshipLength, err := actor.ParseCertificateProviderRelationshipLength(page.PostFormString(r, "relationship-length")) + relationshipLength, err := donordata.ParseCertificateProviderRelationshipLength(page.PostFormString(r, "relationship-length")) return &howLongHaveYouKnownCertificateProviderForm{ RelationshipLength: relationshipLength, diff --git a/internal/page/donor/how_long_have_you_known_certificate_provider_test.go b/internal/page/donor/how_long_have_you_known_certificate_provider_test.go index 79c4cd4796..e4c57194db 100644 --- a/internal/page/donor/how_long_have_you_known_certificate_provider_test.go +++ b/internal/page/donor/how_long_have_you_known_certificate_provider_test.go @@ -9,6 +9,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" @@ -24,7 +25,7 @@ func TestGetHowLongHaveYouKnownCertificateProvider(t *testing.T) { template.EXPECT(). Execute(w, &howLongHaveYouKnownCertificateProviderData{ App: testAppData, - Options: actor.CertificateProviderRelationshipLengthValues, + Options: donordata.CertificateProviderRelationshipLengthValues, }). Return(nil) @@ -47,7 +48,7 @@ func TestGetHowLongHaveYouKnownCertificateProviderFromStore(t *testing.T) { App: testAppData, CertificateProvider: certificateProvider, RelationshipLength: actor.GreaterThanEqualToTwoYears, - Options: actor.CertificateProviderRelationshipLengthValues, + Options: donordata.CertificateProviderRelationshipLengthValues, }). Return(nil) @@ -66,7 +67,7 @@ func TestGetHowLongHaveYouKnownCertificateProviderWhenTemplateErrors(t *testing. template.EXPECT(). Execute(w, &howLongHaveYouKnownCertificateProviderData{ App: testAppData, - Options: actor.CertificateProviderRelationshipLengthValues, + Options: donordata.CertificateProviderRelationshipLengthValues, }). Return(expectedError) @@ -156,7 +157,7 @@ func TestPostHowLongHaveYouKnownCertificateProviderWhenValidationErrors(t *testi Execute(w, &howLongHaveYouKnownCertificateProviderData{ App: testAppData, Errors: validation.With("relationship-length", validation.SelectError{Label: "howLongYouHaveKnownCertificateProvider"}), - Options: actor.CertificateProviderRelationshipLengthValues, + Options: donordata.CertificateProviderRelationshipLengthValues, }). Return(nil) diff --git a/internal/page/donor/how_should_attorneys_make_decisions.go b/internal/page/donor/how_should_attorneys_make_decisions.go index 639a263c9e..03a07f97a1 100644 --- a/internal/page/donor/how_should_attorneys_make_decisions.go +++ b/internal/page/donor/how_should_attorneys_make_decisions.go @@ -5,6 +5,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) @@ -14,7 +15,7 @@ type howShouldAttorneysMakeDecisionsData struct { Errors validation.List Form *howShouldAttorneysMakeDecisionsForm Donor *actor.DonorProvidedDetails - Options actor.AttorneysActOptions + Options donordata.AttorneysActOptions } func HowShouldAttorneysMakeDecisions(tmpl template.Template, donorStore DonorStore) Handler { @@ -26,7 +27,7 @@ func HowShouldAttorneysMakeDecisions(tmpl template.Template, donorStore DonorSto DecisionsDetails: donor.AttorneyDecisions.Details, }, Donor: donor, - Options: actor.AttorneysActValues, + Options: donordata.AttorneysActValues, } if r.Method == http.MethodPost { @@ -69,7 +70,7 @@ type howShouldAttorneysMakeDecisionsForm struct { } func readHowShouldAttorneysMakeDecisionsForm(r *http.Request, errorLabel, detailsErrorLabel string) *howShouldAttorneysMakeDecisionsForm { - how, err := actor.ParseAttorneysAct(page.PostFormString(r, "decision-type")) + how, err := donordata.ParseAttorneysAct(page.PostFormString(r, "decision-type")) return &howShouldAttorneysMakeDecisionsForm{ DecisionsType: how, diff --git a/internal/page/donor/how_should_attorneys_make_decisions_test.go b/internal/page/donor/how_should_attorneys_make_decisions_test.go index 528ce101fb..876769cfd0 100644 --- a/internal/page/donor/how_should_attorneys_make_decisions_test.go +++ b/internal/page/donor/how_should_attorneys_make_decisions_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" "github.com/stretchr/testify/assert" @@ -24,7 +25,7 @@ func TestGetHowShouldAttorneysMakeDecisions(t *testing.T) { App: testAppData, Form: &howShouldAttorneysMakeDecisionsForm{}, Donor: &actor.DonorProvidedDetails{}, - Options: actor.AttorneysActValues, + Options: donordata.AttorneysActValues, }). Return(nil) @@ -48,7 +49,7 @@ func TestGetHowShouldAttorneysMakeDecisionsFromStore(t *testing.T) { DecisionsDetails: "some decisions", }, Donor: &actor.DonorProvidedDetails{AttorneyDecisions: actor.AttorneyDecisions{Details: "some decisions", How: actor.Jointly}}, - Options: actor.AttorneysActValues, + Options: donordata.AttorneysActValues, }). Return(nil) diff --git a/internal/page/donor/how_should_replacement_attorneys_make_decisions.go b/internal/page/donor/how_should_replacement_attorneys_make_decisions.go index 4c48e4e469..b07a21b945 100644 --- a/internal/page/donor/how_should_replacement_attorneys_make_decisions.go +++ b/internal/page/donor/how_should_replacement_attorneys_make_decisions.go @@ -5,6 +5,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) @@ -13,7 +14,7 @@ type howShouldReplacementAttorneysMakeDecisionsData struct { App page.AppData Errors validation.List Form *howShouldAttorneysMakeDecisionsForm - Options actor.AttorneysActOptions + Options donordata.AttorneysActOptions Donor *actor.DonorProvidedDetails } @@ -25,7 +26,7 @@ func HowShouldReplacementAttorneysMakeDecisions(tmpl template.Template, donorSto DecisionsType: donor.ReplacementAttorneyDecisions.How, DecisionsDetails: donor.ReplacementAttorneyDecisions.Details, }, - Options: actor.AttorneysActValues, + Options: donordata.AttorneysActValues, Donor: donor, } diff --git a/internal/page/donor/how_should_replacement_attorneys_make_decisions_test.go b/internal/page/donor/how_should_replacement_attorneys_make_decisions_test.go index dd22abdd41..9dc9060132 100644 --- a/internal/page/donor/how_should_replacement_attorneys_make_decisions_test.go +++ b/internal/page/donor/how_should_replacement_attorneys_make_decisions_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" "github.com/stretchr/testify/assert" @@ -23,7 +24,7 @@ func TestGetHowShouldReplacementAttorneysMakeDecisions(t *testing.T) { Execute(w, &howShouldReplacementAttorneysMakeDecisionsData{ App: testAppData, Form: &howShouldAttorneysMakeDecisionsForm{}, - Options: actor.AttorneysActValues, + Options: donordata.AttorneysActValues, Donor: &actor.DonorProvidedDetails{}, }). Return(nil) @@ -47,7 +48,7 @@ func TestGetHowShouldReplacementAttorneysMakeDecisionsFromStore(t *testing.T) { DecisionsType: actor.Jointly, DecisionsDetails: "some decisions", }, - Options: actor.AttorneysActValues, + Options: donordata.AttorneysActValues, Donor: &actor.DonorProvidedDetails{ReplacementAttorneyDecisions: actor.AttorneyDecisions{Details: "some decisions", How: actor.Jointly}}, }). Return(nil) diff --git a/internal/page/donor/how_should_replacement_attorneys_step_in.go b/internal/page/donor/how_should_replacement_attorneys_step_in.go index 61e53d9c71..5be552ceef 100644 --- a/internal/page/donor/how_should_replacement_attorneys_step_in.go +++ b/internal/page/donor/how_should_replacement_attorneys_step_in.go @@ -5,6 +5,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) @@ -13,7 +14,7 @@ type howShouldReplacementAttorneysStepInData struct { App page.AppData Errors validation.List Form *howShouldReplacementAttorneysStepInForm - Options actor.ReplacementAttorneysStepInOptions + Options donordata.ReplacementAttorneysStepInOptions } func HowShouldReplacementAttorneysStepIn(tmpl template.Template, donorStore DonorStore) Handler { @@ -24,7 +25,7 @@ func HowShouldReplacementAttorneysStepIn(tmpl template.Template, donorStore Dono WhenToStepIn: donor.HowShouldReplacementAttorneysStepIn, OtherDetails: donor.HowShouldReplacementAttorneysStepInDetails, }, - Options: actor.ReplacementAttorneysStepInValues, + Options: donordata.ReplacementAttorneysStepInValues, } if r.Method == http.MethodPost { @@ -65,7 +66,7 @@ type howShouldReplacementAttorneysStepInForm struct { } func readHowShouldReplacementAttorneysStepInForm(r *http.Request) *howShouldReplacementAttorneysStepInForm { - when, err := actor.ParseReplacementAttorneysStepIn(page.PostFormString(r, "when-to-step-in")) + when, err := donordata.ParseReplacementAttorneysStepIn(page.PostFormString(r, "when-to-step-in")) return &howShouldReplacementAttorneysStepInForm{ WhenToStepIn: when, diff --git a/internal/page/donor/how_should_replacement_attorneys_step_in_test.go b/internal/page/donor/how_should_replacement_attorneys_step_in_test.go index fc3a94ab22..29c67f6471 100644 --- a/internal/page/donor/how_should_replacement_attorneys_step_in_test.go +++ b/internal/page/donor/how_should_replacement_attorneys_step_in_test.go @@ -9,6 +9,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" "github.com/stretchr/testify/assert" @@ -24,7 +25,7 @@ func TestGetHowShouldReplacementAttorneysStepIn(t *testing.T) { Execute(w, &howShouldReplacementAttorneysStepInData{ App: testAppData, Form: &howShouldReplacementAttorneysStepInForm{}, - Options: actor.ReplacementAttorneysStepInValues, + Options: donordata.ReplacementAttorneysStepInValues, }). Return(nil) @@ -49,7 +50,7 @@ func TestGetHowShouldReplacementAttorneysStepInFromStore(t *testing.T) { WhenToStepIn: actor.ReplacementAttorneysStepInAnotherWay, OtherDetails: "some details", }, - Options: actor.ReplacementAttorneysStepInValues, + Options: donordata.ReplacementAttorneysStepInValues, }). Return(nil) diff --git a/internal/page/donor/how_would_certificate_provider_prefer_to_carry_out_their_role.go b/internal/page/donor/how_would_certificate_provider_prefer_to_carry_out_their_role.go index d663d70ddb..da0a187ff2 100644 --- a/internal/page/donor/how_would_certificate_provider_prefer_to_carry_out_their_role.go +++ b/internal/page/donor/how_would_certificate_provider_prefer_to_carry_out_their_role.go @@ -5,6 +5,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) @@ -14,7 +15,7 @@ type howWouldCertificateProviderPreferToCarryOutTheirRoleData struct { Errors validation.List CertificateProvider actor.CertificateProvider Form *howWouldCertificateProviderPreferToCarryOutTheirRoleForm - Options actor.ChannelOptions + Options donordata.ChannelOptions } func HowWouldCertificateProviderPreferToCarryOutTheirRole(tmpl template.Template, donorStore DonorStore) Handler { @@ -26,7 +27,7 @@ func HowWouldCertificateProviderPreferToCarryOutTheirRole(tmpl template.Template CarryOutBy: donor.CertificateProvider.CarryOutBy, Email: donor.CertificateProvider.Email, }, - Options: actor.ChannelValues, + Options: donordata.ChannelValues, } if r.Method == http.MethodPost { @@ -56,7 +57,7 @@ type howWouldCertificateProviderPreferToCarryOutTheirRoleForm struct { } func readHowWouldCertificateProviderPreferToCarryOutTheirRole(r *http.Request) *howWouldCertificateProviderPreferToCarryOutTheirRoleForm { - channel, err := actor.ParseChannel(page.PostFormString(r, "carry-out-by")) + channel, err := donordata.ParseChannel(page.PostFormString(r, "carry-out-by")) email := page.PostFormString(r, "email") if channel.IsPaper() { diff --git a/internal/page/donor/how_would_certificate_provider_prefer_to_carry_out_their_role_test.go b/internal/page/donor/how_would_certificate_provider_prefer_to_carry_out_their_role_test.go index b33c92096c..4563cdd3d4 100644 --- a/internal/page/donor/how_would_certificate_provider_prefer_to_carry_out_their_role_test.go +++ b/internal/page/donor/how_would_certificate_provider_prefer_to_carry_out_their_role_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" "github.com/stretchr/testify/assert" @@ -23,7 +24,7 @@ func TestGetHowWouldCertificateProviderPreferToCarryOutTheirRole(t *testing.T) { Execute(w, &howWouldCertificateProviderPreferToCarryOutTheirRoleData{ App: testAppData, Form: &howWouldCertificateProviderPreferToCarryOutTheirRoleForm{}, - Options: actor.ChannelValues, + Options: donordata.ChannelValues, }). Return(nil) @@ -44,7 +45,7 @@ func TestGetHowWouldCertificateProviderPreferToCarryOutTheirRoleFromStore(t *tes App: testAppData, CertificateProvider: actor.CertificateProvider{CarryOutBy: actor.ChannelPaper}, Form: &howWouldCertificateProviderPreferToCarryOutTheirRoleForm{CarryOutBy: actor.ChannelPaper}, - Options: actor.ChannelValues, + Options: donordata.ChannelValues, }). Return(nil) @@ -66,7 +67,7 @@ func TestGetHowWouldCertificateProviderPreferToCarryOutTheirRoleWhenTemplateErro Execute(w, &howWouldCertificateProviderPreferToCarryOutTheirRoleData{ App: testAppData, Form: &howWouldCertificateProviderPreferToCarryOutTheirRoleForm{}, - Options: actor.ChannelValues, + Options: donordata.ChannelValues, }). Return(expectedError) diff --git a/internal/page/donor/life_sustaining_treatment.go b/internal/page/donor/life_sustaining_treatment.go index b85ec52651..e6d8451cce 100644 --- a/internal/page/donor/life_sustaining_treatment.go +++ b/internal/page/donor/life_sustaining_treatment.go @@ -5,6 +5,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) @@ -13,7 +14,7 @@ type lifeSustainingTreatmentData struct { App page.AppData Errors validation.List Form *lifeSustainingTreatmentForm - Options actor.LifeSustainingTreatmentOptions + Options donordata.LifeSustainingTreatmentOptions } func LifeSustainingTreatment(tmpl template.Template, donorStore DonorStore) Handler { @@ -23,7 +24,7 @@ func LifeSustainingTreatment(tmpl template.Template, donorStore DonorStore) Hand Form: &lifeSustainingTreatmentForm{ Option: donor.LifeSustainingTreatmentOption, }, - Options: actor.LifeSustainingTreatmentValues, + Options: donordata.LifeSustainingTreatmentValues, } if r.Method == http.MethodPost { @@ -51,7 +52,7 @@ type lifeSustainingTreatmentForm struct { } func readLifeSustainingTreatmentForm(r *http.Request) *lifeSustainingTreatmentForm { - option, err := actor.ParseLifeSustainingTreatment(page.PostFormString(r, "option")) + option, err := donordata.ParseLifeSustainingTreatment(page.PostFormString(r, "option")) return &lifeSustainingTreatmentForm{ Option: option, diff --git a/internal/page/donor/life_sustaining_treatment_test.go b/internal/page/donor/life_sustaining_treatment_test.go index 98d002f1de..ab02604f15 100644 --- a/internal/page/donor/life_sustaining_treatment_test.go +++ b/internal/page/donor/life_sustaining_treatment_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" "github.com/stretchr/testify/assert" @@ -23,7 +24,7 @@ func TestGetLifeSustainingTreatment(t *testing.T) { Execute(w, &lifeSustainingTreatmentData{ App: testAppData, Form: &lifeSustainingTreatmentForm{}, - Options: actor.LifeSustainingTreatmentValues, + Options: donordata.LifeSustainingTreatmentValues, }). Return(nil) @@ -45,7 +46,7 @@ func TestGetLifeSustainingTreatmentFromStore(t *testing.T) { Form: &lifeSustainingTreatmentForm{ Option: actor.LifeSustainingTreatmentOptionA, }, - Options: actor.LifeSustainingTreatmentValues, + Options: donordata.LifeSustainingTreatmentValues, }). Return(nil) diff --git a/internal/page/donor/lpa_type.go b/internal/page/donor/lpa_type.go index 7e5f05927a..a5272a616b 100644 --- a/internal/page/donor/lpa_type.go +++ b/internal/page/donor/lpa_type.go @@ -5,6 +5,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/uid" @@ -15,7 +16,7 @@ type lpaTypeData struct { App page.AppData Errors validation.List Form *lpaTypeForm - Options actor.LpaTypeOptions + Options donordata.LpaTypeOptions } func LpaType(tmpl template.Template, donorStore DonorStore, eventClient EventClient) Handler { @@ -25,7 +26,7 @@ func LpaType(tmpl template.Template, donorStore DonorStore, eventClient EventCli Form: &lpaTypeForm{ LpaType: donor.Type, }, - Options: actor.LpaTypeValues, + Options: donordata.LpaTypeValues, } if r.Method == http.MethodPost { @@ -77,7 +78,7 @@ type lpaTypeForm struct { } func readLpaTypeForm(r *http.Request) *lpaTypeForm { - lpaType, err := actor.ParseLpaType(page.PostFormString(r, "lpa-type")) + lpaType, err := donordata.ParseLpaType(page.PostFormString(r, "lpa-type")) return &lpaTypeForm{ LpaType: lpaType, diff --git a/internal/page/donor/lpa_type_test.go b/internal/page/donor/lpa_type_test.go index bfac0ecdda..02a850d56d 100644 --- a/internal/page/donor/lpa_type_test.go +++ b/internal/page/donor/lpa_type_test.go @@ -10,6 +10,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" @@ -28,7 +29,7 @@ func TestGetLpaType(t *testing.T) { Execute(w, &lpaTypeData{ App: testAppData, Form: &lpaTypeForm{}, - Options: actor.LpaTypeValues, + Options: donordata.LpaTypeValues, }). Return(nil) @@ -50,7 +51,7 @@ func TestGetLpaTypeFromStore(t *testing.T) { Form: &lpaTypeForm{ LpaType: actor.LpaTypePropertyAndAffairs, }, - Options: actor.LpaTypeValues, + Options: donordata.LpaTypeValues, }). Return(nil) diff --git a/internal/page/donor/when_can_the_lpa_be_used.go b/internal/page/donor/when_can_the_lpa_be_used.go index 01f306f90d..1aa18a42e3 100644 --- a/internal/page/donor/when_can_the_lpa_be_used.go +++ b/internal/page/donor/when_can_the_lpa_be_used.go @@ -5,6 +5,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) @@ -14,7 +15,7 @@ type whenCanTheLpaBeUsedData struct { Errors validation.List Donor *actor.DonorProvidedDetails Form *whenCanTheLpaBeUsedForm - Options actor.CanBeUsedWhenOptions + Options donordata.CanBeUsedWhenOptions } func WhenCanTheLpaBeUsed(tmpl template.Template, donorStore DonorStore) Handler { @@ -25,7 +26,7 @@ func WhenCanTheLpaBeUsed(tmpl template.Template, donorStore DonorStore) Handler Form: &whenCanTheLpaBeUsedForm{ When: donor.WhenCanTheLpaBeUsed, }, - Options: actor.CanBeUsedWhenValues, + Options: donordata.CanBeUsedWhenValues, } if r.Method == http.MethodPost { @@ -53,7 +54,7 @@ type whenCanTheLpaBeUsedForm struct { } func readWhenCanTheLpaBeUsedForm(r *http.Request) *whenCanTheLpaBeUsedForm { - when, err := actor.ParseCanBeUsedWhen(page.PostFormString(r, "when")) + when, err := donordata.ParseCanBeUsedWhen(page.PostFormString(r, "when")) return &whenCanTheLpaBeUsedForm{ When: when, diff --git a/internal/page/donor/when_can_the_lpa_be_used_test.go b/internal/page/donor/when_can_the_lpa_be_used_test.go index 1c4b8a05c3..ad55126291 100644 --- a/internal/page/donor/when_can_the_lpa_be_used_test.go +++ b/internal/page/donor/when_can_the_lpa_be_used_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" "github.com/stretchr/testify/assert" @@ -24,7 +25,7 @@ func TestGetWhenCanTheLpaBeUsed(t *testing.T) { App: testAppData, Donor: &actor.DonorProvidedDetails{}, Form: &whenCanTheLpaBeUsedForm{}, - Options: actor.CanBeUsedWhenValues, + Options: donordata.CanBeUsedWhenValues, }). Return(nil) @@ -47,7 +48,7 @@ func TestGetWhenCanTheLpaBeUsedFromStore(t *testing.T) { Form: &whenCanTheLpaBeUsedForm{ When: actor.CanBeUsedWhenHasCapacity, }, - Options: actor.CanBeUsedWhenValues, + Options: donordata.CanBeUsedWhenValues, }). Return(nil) diff --git a/internal/page/donor/who_can_correspondents_details_be_shared_with.go b/internal/page/donor/who_can_correspondents_details_be_shared_with.go index 25c4ad7782..a3079a3272 100644 --- a/internal/page/donor/who_can_correspondents_details_be_shared_with.go +++ b/internal/page/donor/who_can_correspondents_details_be_shared_with.go @@ -5,6 +5,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) @@ -13,7 +14,7 @@ type whoCanCorrespondentsDetailsBeSharedWithData struct { App page.AppData Errors validation.List Form *whoCanCorrespondentsDetailsBeSharedWithForm - Options actor.CorrespondentShareOptions + Options donordata.CorrespondentShareOptions } func WhoCanCorrespondentsDetailsBeSharedWith(tmpl template.Template, donorStore DonorStore) Handler { @@ -23,7 +24,7 @@ func WhoCanCorrespondentsDetailsBeSharedWith(tmpl template.Template, donorStore Form: &whoCanCorrespondentsDetailsBeSharedWithForm{ Share: donor.Correspondent.Share, }, - Options: actor.CorrespondentShareValues, + Options: donordata.CorrespondentShareValues, } if r.Method == http.MethodPost { @@ -53,7 +54,7 @@ type whoCanCorrespondentsDetailsBeSharedWithForm struct { func readWhoCanCorrespondentsDetailsBeSharedWithForm(r *http.Request) *whoCanCorrespondentsDetailsBeSharedWithForm { r.ParseForm() - share, err := actor.ParseCorrespondentShare(r.PostForm["share"]) + share, err := donordata.ParseCorrespondentShare(r.PostForm["share"]) return &whoCanCorrespondentsDetailsBeSharedWithForm{ Share: share, diff --git a/internal/page/donor/who_can_correspondents_details_be_shared_with_test.go b/internal/page/donor/who_can_correspondents_details_be_shared_with_test.go index 9f875d66e9..77f9d7b3c4 100644 --- a/internal/page/donor/who_can_correspondents_details_be_shared_with_test.go +++ b/internal/page/donor/who_can_correspondents_details_be_shared_with_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" "github.com/stretchr/testify/assert" @@ -23,7 +24,7 @@ func TestGetWhoCanCorrespondentsDetailsBeSharedWith(t *testing.T) { Execute(w, &whoCanCorrespondentsDetailsBeSharedWithData{ App: testAppData, Form: &whoCanCorrespondentsDetailsBeSharedWithForm{}, - Options: actor.CorrespondentShareValues, + Options: donordata.CorrespondentShareValues, }). Return(nil) @@ -45,7 +46,7 @@ func TestGetWhoCanCorrespondentsDetailsBeSharedWithFromStore(t *testing.T) { Form: &whoCanCorrespondentsDetailsBeSharedWithForm{ Share: actor.CorrespondentShareAttorneys, }, - Options: actor.CorrespondentShareValues, + Options: donordata.CorrespondentShareValues, }). Return(nil) diff --git a/internal/pay/enum_evidencedelivery.go b/internal/pay/enum_evidencedelivery.go index af7dd92f2e..c60dd02976 100644 --- a/internal/pay/enum_evidencedelivery.go +++ b/internal/pay/enum_evidencedelivery.go @@ -19,9 +19,6 @@ const _EvidenceDelivery_name = "uploadpost" var _EvidenceDelivery_index = [...]uint8{0, 6, 10} func (i EvidenceDelivery) String() string { - if i == 0 { - return "" - } i -= 1 if i >= EvidenceDelivery(len(_EvidenceDelivery_index)-1) { return "EvidenceDelivery(" + strconv.FormatInt(int64(i+1), 10) + ")" diff --git a/internal/pay/enum_previousfee.go b/internal/pay/enum_previousfee.go index 68b84c54ad..680d8ea01f 100644 --- a/internal/pay/enum_previousfee.go +++ b/internal/pay/enum_previousfee.go @@ -21,9 +21,6 @@ const _PreviousFee_name = "FullHalfExemptionHardship" var _PreviousFee_index = [...]uint8{0, 4, 8, 17, 25} func (i PreviousFee) String() string { - if i == 0 { - return "" - } i -= 1 if i >= PreviousFee(len(_PreviousFee_index)-1) { return "PreviousFee(" + strconv.FormatInt(int64(i+1), 10) + ")"