feat(android): add testable F5 workflow rules
This commit is contained in:
+54
@@ -0,0 +1,54 @@
|
||||
package com.korexlabs.dhinspeccion.domain
|
||||
|
||||
/**
|
||||
* UX-side mirrors of server invariants used to prevent invalid field actions before a request is sent.
|
||||
* The API remains authoritative; these rules must never be used to weaken backend validation.
|
||||
*/
|
||||
object MobileWorkflowRules {
|
||||
private val validUrgencies = setOf("URGENT", "NON_URGENT")
|
||||
private val terminalCompanyOutcomes = setOf("SIGNED", "REFUSED")
|
||||
|
||||
fun canStartInspection(status: String): Boolean = status == "PLANNED"
|
||||
|
||||
fun hasDraftAct(statuses: Iterable<String>): Boolean = statuses.any { it == "DRAFT" }
|
||||
|
||||
fun canCreateAct(
|
||||
visitStatus: String,
|
||||
actStatuses: Iterable<String>,
|
||||
hasSelectedInventory: Boolean,
|
||||
urgency: String,
|
||||
): Boolean =
|
||||
visitStatus == "IN_PROGRESS" &&
|
||||
!hasDraftAct(actStatuses) &&
|
||||
hasSelectedInventory &&
|
||||
urgency in validUrgencies
|
||||
|
||||
fun canCreateFieldInventory(visitStatus: String): Boolean = visitStatus == "IN_PROGRESS"
|
||||
|
||||
fun canRegisterFinding(
|
||||
visitStatus: String,
|
||||
selectedActStatus: String?,
|
||||
inventoryReadyForFinding: Boolean,
|
||||
): Boolean =
|
||||
visitStatus == "IN_PROGRESS" &&
|
||||
selectedActStatus == "DRAFT" &&
|
||||
inventoryReadyForFinding
|
||||
|
||||
fun canLockAct(actStatus: String?, responsibleDefined: Boolean): Boolean =
|
||||
actStatus == "DRAFT" && responsibleDefined
|
||||
|
||||
fun canSealAct(
|
||||
actStatus: String?,
|
||||
inspectorSigned: Boolean,
|
||||
companyOutcomeStatus: String?,
|
||||
): Boolean =
|
||||
actStatus == "LOCKED" &&
|
||||
inspectorSigned &&
|
||||
companyOutcomeStatus in terminalCompanyOutcomes
|
||||
|
||||
fun canCloseInspection(visitStatus: String, actStatuses: Iterable<String>): Boolean {
|
||||
if (visitStatus != "IN_PROGRESS") return false
|
||||
val active = actStatuses.filter { it != "CANCELLED" }
|
||||
return active.isNotEmpty() && active.all { it == "SEALED" }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user