Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package uk.gov.hmrc.agentregistration.shared

import uk.gov.hmrc.agentregistration.shared.agentdetails.AgentDetails
import uk.gov.hmrc.agentregistration.shared.audit.SessionId
import uk.gov.hmrc.agentregistration.shared.businessdetails.*
import uk.gov.hmrc.agentregistration.shared.contactdetails.ApplicantContactDetails
import uk.gov.hmrc.agentregistration.shared.lists.FiveOrLess
Expand All @@ -35,6 +36,7 @@ import java.time.Instant
sealed trait AgentApplication:

def _id: AgentApplicationId
def cachedSessionId: SessionId
def applicationReference: ApplicationReference
def internalUserId: InternalUserId
def applicantCredentials: Credentials
Expand Down Expand Up @@ -147,6 +149,7 @@ sealed trait AgentApplication:
*/
final case class AgentApplicationSoleTrader(
override val _id: AgentApplicationId,
override val cachedSessionId: SessionId,
override val applicationReference: ApplicationReference,
override val internalUserId: InternalUserId,
override val applicantCredentials: Credentials,
Expand Down Expand Up @@ -181,6 +184,7 @@ object AgentApplicationSoleTrader:
*/
final case class AgentApplicationLlp(
override val _id: AgentApplicationId,
override val cachedSessionId: SessionId,
override val applicationReference: ApplicationReference,
override val internalUserId: InternalUserId,
override val applicantCredentials: Credentials,
Expand Down Expand Up @@ -213,6 +217,7 @@ extends AgentApplication:
*/
final case class AgentApplicationLimitedCompany(
override val _id: AgentApplicationId,
override val cachedSessionId: SessionId,
override val applicationReference: ApplicationReference,
override val internalUserId: InternalUserId,
override val applicantCredentials: Credentials,
Expand Down Expand Up @@ -245,6 +250,7 @@ extends AgentApplication:
*/
final case class AgentApplicationGeneralPartnership(
override val _id: AgentApplicationId,
override val cachedSessionId: SessionId,
override val applicationReference: ApplicationReference,
override val internalUserId: InternalUserId,
override val applicantCredentials: Credentials,
Expand Down Expand Up @@ -275,6 +281,7 @@ extends AgentApplication:
*/
final case class AgentApplicationLimitedPartnership(
override val _id: AgentApplicationId,
override val cachedSessionId: SessionId,
override val applicationReference: ApplicationReference,
override val internalUserId: InternalUserId,
override val applicantCredentials: Credentials,
Expand Down Expand Up @@ -305,6 +312,7 @@ extends AgentApplication:

final case class AgentApplicationScottishLimitedPartnership(
override val _id: AgentApplicationId,
override val cachedSessionId: SessionId,
override val applicationReference: ApplicationReference,
override val internalUserId: InternalUserId,
override val applicantCredentials: Credentials,
Expand Down Expand Up @@ -335,6 +343,7 @@ extends AgentApplication:

final case class AgentApplicationScottishPartnership(
override val _id: AgentApplicationId,
override val cachedSessionId: SessionId,
override val applicationReference: ApplicationReference,
override val internalUserId: InternalUserId,
override val applicantCredentials: Credentials,
Expand Down
60 changes: 60 additions & 0 deletions app/uk/gov/hmrc/agentregistration/shared/audit/AuditEvent.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2026 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package uk.gov.hmrc.agentregistration.shared.audit

import play.api.libs.json.Format
import play.api.libs.json.Json
import play.api.libs.json.OFormat
import uk.gov.hmrc.agentregistration.shared.util.JsonFormatsFactory
import uk.gov.hmrc.agentregistration.shared.AgentApplication
import uk.gov.hmrc.agentregistration.shared.ApplicationReference
import uk.gov.hmrc.agentregistration.shared.BusinessType

sealed trait AuditEvent:

val applicationReference: ApplicationReference
val auditType: String = this.getClass.getSimpleName

// The application does not support non-uk for now so isUkEntity is set to always true
final case class StartOrContinueApplication(
applicationReference: ApplicationReference,
journeyType: StartOrContinueApplication.JourneyType,
entityType: BusinessType,
isUkEntity: Boolean = true
)
extends AuditEvent

object StartOrContinueApplication:

def make(
agentApplication: AgentApplication,
journeyType: JourneyType
): StartOrContinueApplication = StartOrContinueApplication(
applicationReference = agentApplication.applicationReference,
journeyType = journeyType,
entityType = agentApplication.businessType
)

given format: Format[StartOrContinueApplication] = Json.format[StartOrContinueApplication]

enum JourneyType:

case Start
case Continue

object JourneyType:
given format: Format[JourneyType] = JsonFormatsFactory.makeEnumFormat
26 changes: 26 additions & 0 deletions app/uk/gov/hmrc/agentregistration/shared/audit/SessionId.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2026 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package uk.gov.hmrc.agentregistration.shared.audit

import play.api.libs.json.Format
import uk.gov.hmrc.agentregistration.shared.util.JsonFormatsFactory

final case class SessionId(value: String)

object SessionId:

given format: Format[SessionId] = JsonFormatsFactory.makeValueClassFormat
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ object IndividualDateOfBirth:
final case class Provided(dateOfBirth: LocalDate)
extends UserProvidedDateOfBirth

final case class ApplicantProvided(dateOfBirth: LocalDate)
extends UserProvidedDateOfBirth

final case class FromCitizensDetails(dateOfBirth: LocalDate)
extends IndividualDateOfBirth

Expand All @@ -45,6 +48,7 @@ object IndividualDateOfBirth:
given OFormat[IndividualDateOfBirth] =
given JsonConfiguration = JsonConfig.jsonConfiguration
given OFormat[Provided] = Json.format[Provided]
given OFormat[ApplicantProvided] = Json.format[ApplicantProvided]
given OFormat[FromCitizensDetails] = Json.format[FromCitizensDetails]

val dontDeleteMe = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package uk.gov.hmrc.agentregistration.shared.testdata

import uk.gov.hmrc.agentregistration.shared.*
import uk.gov.hmrc.agentregistration.shared.agentdetails.*
import uk.gov.hmrc.agentregistration.shared.audit.SessionId
import uk.gov.hmrc.agentregistration.shared.businessdetails.CompanyProfile
import uk.gov.hmrc.agentregistration.shared.businessdetails.FullName
import uk.gov.hmrc.agentregistration.shared.companieshouse.ChroAddress
Expand Down Expand Up @@ -63,6 +64,7 @@ trait TdBase:

final val clock: Clock = Clock.fixed(nowAsInstant, zoneId)

def cachedSessionId: SessionId = SessionId("session-id-123")
def saUtr: SaUtr = SaUtr("1234567895")
def ctUtr: CtUtr = CtUtr("2202108031")
def internalUserId: InternalUserId = InternalUserId("internal-user-id-12345")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ trait TdAgentApplicationGeneralPartnership { dependencies: (TdBase & TdGrsBusine

val afterStarted: AgentApplicationGeneralPartnership = AgentApplicationGeneralPartnership(
_id = dependencies.agentApplicationId,
cachedSessionId = dependencies.cachedSessionId,
applicationReference = dependencies.applicationReference,
internalUserId = dependencies.internalUserId,
applicantCredentials = dependencies.credentials,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ trait TdAgentApplicationLimitedCompany { dependencies: (TdBase & TdGrsBusinessDe

val afterStarted: AgentApplicationLimitedCompany = AgentApplicationLimitedCompany(
_id = dependencies.agentApplicationId,
cachedSessionId = dependencies.cachedSessionId,
applicationReference = dependencies.applicationReference,
internalUserId = dependencies.internalUserId,
applicantCredentials = dependencies.credentials,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ trait TdAgentApplicationLimitedPartnership {

val afterStarted: AgentApplicationLimitedPartnership = AgentApplicationLimitedPartnership(
_id = dependencies.agentApplicationId,
cachedSessionId = dependencies.cachedSessionId,
applicationReference = dependencies.applicationReference,
internalUserId = dependencies.internalUserId,
applicantCredentials = dependencies.credentials,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ trait TdAgentApplicationLlp { dependencies: (TdBase & TdGrsBusinessDetails) =>

val afterStarted: AgentApplicationLlp = AgentApplicationLlp(
_id = dependencies.agentApplicationId,
cachedSessionId = dependencies.cachedSessionId,
applicationReference = dependencies.applicationReference,
internalUserId = dependencies.internalUserId,
applicantCredentials = dependencies.credentials,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ trait TdAgentApplicationScottishLimitedPartnership {

val afterStarted: AgentApplicationScottishLimitedPartnership = AgentApplicationScottishLimitedPartnership(
_id = dependencies.agentApplicationId,
cachedSessionId = dependencies.cachedSessionId,
applicationReference = dependencies.applicationReference,
internalUserId = dependencies.internalUserId,
applicantCredentials = dependencies.credentials,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ trait TdAgentApplicationScottishPartnership { dependencies: (TdBase & TdGrsBusin

val afterStarted: AgentApplicationScottishPartnership = AgentApplicationScottishPartnership(
_id = dependencies.agentApplicationId,
cachedSessionId = dependencies.cachedSessionId,
applicationReference = dependencies.applicationReference,
internalUserId = dependencies.internalUserId,
applicantCredentials = dependencies.credentials,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ trait TdAgentApplicationSoleTrader { dependencies: (TdBase & TdGrsBusinessDetail

val afterStarted: AgentApplicationSoleTrader = AgentApplicationSoleTrader(
_id = dependencies.agentApplicationId,
cachedSessionId = dependencies.cachedSessionId,
applicationReference = dependencies.applicationReference,
internalUserId = dependencies.internalUserId,
applicantCredentials = dependencies.credentials,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ trait TdAgentApplicationSoleTraderRepresentative { dependencies: (TdBase & TdGrs

val afterStarted: AgentApplicationSoleTrader = AgentApplicationSoleTrader(
_id = dependencies.agentApplicationId,
cachedSessionId = dependencies.cachedSessionId,
applicationReference = dependencies.applicationReference,
internalUserId = dependencies.internalUserId,
applicantCredentials = dependencies.credentials,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ final case class RiskingFileDataRecord(

private def getDobString: String = individualProvidedDateOfBirth.map {
case IndividualDateOfBirth.Provided(dob) => asMinervaDate(dob)
case IndividualDateOfBirth.ApplicantProvided(dob) => asMinervaDate(dob)
case IndividualDateOfBirth.FromCitizensDetails(dob) => asMinervaDate(dob)
}.getOrElse("")

Expand Down