|
| 1 | +package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps |
| 2 | + |
| 3 | +import com.fasterxml.jackson.databind.ObjectMapper |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema |
| 5 | +import jakarta.validation.Valid |
| 6 | +import jakarta.validation.constraints.NotBlank |
| 7 | +import jakarta.validation.constraints.NotNull |
| 8 | +import java.time.LocalDateTime |
| 9 | + |
| 10 | +@Schema(description = "Private prison visit request") |
| 11 | +data class CreateVisitRequest( |
| 12 | + @Schema(description = "Prisoner Id", example = "AF34567G", required = true) |
| 13 | + @field:NotBlank |
| 14 | + val prisonerId: String, |
| 15 | + @Schema(description = "Prison Id", example = "3-character code, example = MDI", required = true) |
| 16 | + @field:NotBlank |
| 17 | + val prisonId: String, |
| 18 | + @Schema(description = "Client visit reference", example = "Reference ID in the client system", required = true) |
| 19 | + @field:NotBlank |
| 20 | + val clientVisitReference: String, |
| 21 | + @Schema(description = "Visit Room", example = "A1", required = true) |
| 22 | + @field:NotBlank |
| 23 | + val visitRoom: String, |
| 24 | + @Schema(description = "Visit Type", example = "SOCIAL", required = true) |
| 25 | + @field:NotNull |
| 26 | + val visitType: VisitType, |
| 27 | + @Schema(description = "Visit Status", example = "BOOKED", required = true) |
| 28 | + @field:NotNull |
| 29 | + val visitStatus: VisitStatus, |
| 30 | + @Schema(description = "Visit Restriction", example = "OPEN", required = true) |
| 31 | + @field:NotNull |
| 32 | + val visitRestriction: VisitRestriction, |
| 33 | + @Schema(description = "The date and time of the visit", example = "2018-12-01T13:45:00", required = true) |
| 34 | + @field:NotNull |
| 35 | + val startTimestamp: LocalDateTime, |
| 36 | + @Schema(description = "The finishing date and time of the visit", example = "2018-12-01T13:45:00", required = true) |
| 37 | + @field:NotNull |
| 38 | + val endTimestamp: LocalDateTime, |
| 39 | + @Schema(description = "The date and time of when the visit was created in NEXUS", example = "2018-12-01T13:45:00", required = false) |
| 40 | + val createDateTime: LocalDateTime? = null, |
| 41 | + @Schema(description = "List of visitors associated with the visit", required = false) |
| 42 | + val visitors: Set<@Valid Visitor>? = setOf(), |
| 43 | + @Schema(description = "Username for user who actioned this request", required = false) |
| 44 | + val actionedBy: String?, |
| 45 | +) { |
| 46 | + fun toVisitQueueEvent(who: String): VisitQueueEvent { |
| 47 | + val objectMapper = ObjectMapper() |
| 48 | + |
| 49 | + return VisitQueueEvent( |
| 50 | + eventType = VisitQueueEventType.CREATE, |
| 51 | + payload = objectMapper.writeValueAsString(modelToMap()), |
| 52 | + who = who, |
| 53 | + ) |
| 54 | + } |
| 55 | + |
| 56 | + private fun modelToMap(): Map<String, Any?> = |
| 57 | + mapOf( |
| 58 | + "prisonerId" to this.prisonerId, |
| 59 | + "prisonId" to this.prisonId, |
| 60 | + "clientVisitReference" to this.clientVisitReference, |
| 61 | + "visitRoom" to this.visitRoom, |
| 62 | + "visitType" to this.visitType, |
| 63 | + "visitStatus" to this.visitStatus, |
| 64 | + "visitRestriction" to this.visitRestriction, |
| 65 | + "startTimestamp" to this.startTimestamp.toString(), |
| 66 | + "endTimestamp" to this.endTimestamp.toString(), |
| 67 | + "createDateTime" to this.createDateTime.toString(), |
| 68 | + "visitors" to this.visitors?.map { mapOf("nomisPersonId" to it.nomisPersonId, "visitContact" to it.visitContact) }, |
| 69 | + "actionedBy" to this.actionedBy, |
| 70 | + ) |
| 71 | +} |
0 commit comments