-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial interface design for sanity checks
Part of #137
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.zenmo.zummon.companysurvey | ||
|
||
fun interface Validator { | ||
fun validate(survey: Survey): ValidationResult | ||
} | ||
|
||
data class ValidationResult( | ||
val status: Status, | ||
val message: String, | ||
) | ||
|
||
enum class Status { | ||
VALID, | ||
INVALID, | ||
MISSING_DATA, | ||
} | ||
|
||
val validateContractedCapacity = Validator { survey: Survey -> | ||
val gridConnection = survey.getSingleGridConnection() | ||
|
||
val contractedConnectionCapacity = gridConnection.electricity.getContractedConnectionCapacityKw() | ||
val physicalConnectionCapacity = gridConnection.electricity.getPhysicalConnectionCapacityKw() | ||
|
||
return@Validator when { | ||
contractedConnectionCapacity == null -> ValidationResult( | ||
status = Status.MISSING_DATA, | ||
message = "No contracted connection capacity given", | ||
) | ||
physicalConnectionCapacity == null -> ValidationResult( | ||
status = Status.MISSING_DATA, | ||
message = "No physical connection capacity given", | ||
) | ||
contractedConnectionCapacity <= physicalConnectionCapacity -> ValidationResult( | ||
status = Status.VALID, | ||
message = "Contracted connection capacity fits within physical connection", | ||
) | ||
else -> ValidationResult( | ||
status = Status.INVALID, | ||
message = "Contracted connection capacity ${gridConnection.electricity.getContractedConnectionCapacityKw()} kW is too large for physical connection ${gridConnection.electricity.getPhysicalConnectionCapacityKw()}" | ||
) | ||
} | ||
} |