GuardResult
Result of a guard system check. Immutable record that indicates whether an order is allowed and provides a reason if blocked.
GuardResult.java
package com.bookmap.ordermanagement.model;
/**
* Result of a guard system check.
*
* Immutable record that indicates whether an order is allowed
* and provides a reason if blocked.
*/
public record GuardResult(boolean allowed, String reason, String guardName) {
// Pre-built success result (reusable)
private static final GuardResult SUCCESS = new GuardResult(true, null, null);
/**
* Creates a successful result (order allowed).
*/
public static GuardResult allow() {
return SUCCESS;
}
/**
* Creates a blocked result with reason.
*/
public static GuardResult block(String guardName, String reason) {
return new GuardResult(false, reason, guardName);
}
/**
* Returns true if the order is allowed.
*/
public boolean isAllowed() {
return allowed;
}
/**
* Returns true if the order is blocked.
*/
public boolean isBlocked() {
return !allowed;
}
/**
* Returns the reason for blocking, or null if allowed.
* @deprecated Use {@link #reason()} instead
*/
@Deprecated
public String getReason() {
return reason;
}
/**
* Returns the name of the guard that blocked, or null if allowed.
* @deprecated Use {@link #guardName()} instead
*/
@Deprecated
public String getGuardName() {
return guardName;
}
/**
* Returns a formatted message for logging.
*/
public String toLogMessage() {
if (allowed) {
return "ALLOWED";
}
return String.format("BLOCKED by %s: %s", guardName, reason);
}
@Override
public String toString() {
return toLogMessage();
}
}