evaluate static method
FrequencyEvalResult
evaluate(
- FrequencyPolicy policy,
- FrequencyState? state,
- int now,
- String? sessionId,
Pure eligibility check. Blocks if ANY active constraint is exceeded: permanent stop, lifetime total, or the current window.
Implementation
static FrequencyEvalResult evaluate(
FrequencyPolicy policy,
FrequencyState? state,
int now,
String? sessionId,
) {
if (state == null) return FrequencyEvalResult.allowed;
if (state.stoppedAt != null) {
return const FrequencyEvalResult(false, FrequencySkipReason.stopped);
}
final maxTotal = policy.maxTotal;
if (maxTotal != null && state.total >= maxTotal) {
return const FrequencyEvalResult(false, FrequencySkipReason.maxTotal);
}
final w = policy.maxPerWindow;
if (w != null) {
final effective =
_isWindowExpired(w, state, now, sessionId) ? 0 : state.windowCount;
if (effective >= w.count) {
return const FrequencyEvalResult(false, FrequencySkipReason.window);
}
}
return FrequencyEvalResult.allowed;
}