Implement threshold compliance rule evaluator
epic-bufdir-report-preview-core-logic-task-003 — Implement the threshold compliance rule class. For numeric fields that have a Bufdir-defined minimum value (configured via an injected BufdirThresholdConfig map), compare the field value against the minimum. Return a ValidationIssue with severity 'warning', ruleClass 'threshold', field key, and a message such as 'Activity count (3) is below the required minimum of 5 for category X.' Config must be injectable to support per-organization overrides.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 1 - 540 tasks
Can start after Tier 0 completes
Implementation Notes
Define ThresholdEntry as an immutable value object: class ThresholdEntry { final num minimum; final String categoryLabel; }. BufdirThresholdConfig wraps a Map
Testing Requirements
Unit tests using flutter_test. Test class: ThresholdComplianceRuleEvaluatorTest. Required scenarios: (1) value == minimum → no issue, (2) value > minimum → no issue, (3) value < minimum → warning issued with correct message content, (4) field not in config → no issue, (5) null value with configured minimum → warning issued treating null as zero, (6) integer field value evaluated correctly, (7) double field value evaluated correctly, (8) multiple fields below threshold → one issue per field, (9) override config (org-specific lower threshold) applied correctly. Assert message content (actual value, minimum, category label) in scenario 3.
Minimum 90% line coverage.
The exact minimum threshold values required by Bufdir guidelines (e.g., minimum participant counts per section) may not be formally documented in machine-readable form. If thresholds must be researched or negotiated during implementation, the validation service will be delayed and may launch with incomplete rules, reducing its effectiveness.
Mitigation & Contingency
Mitigation: Compile threshold rules from the Bufdir reporting guidelines PDF before sprint start. Store rules in a separate configuration file (not hardcoded in the service class) so they can be updated without a service rewrite. Treat unknown thresholds as 'no minimum' to avoid false errors.
Contingency: Launch with completeness and anomaly validation only, shipping threshold compliance rules as a follow-on config update once rules are confirmed with Bufdir. Flag this as a known limitation in the coordinator help text.
BufdirPreviewService coordinates three async operations (fetch aggregated data, map structure, run validation). Race conditions or partial failures in this chain could produce an inconsistent preview model — e.g., a model with field values but no validation results — which would silently mislead coordinators into thinking the report is clean.
Mitigation & Contingency
Mitigation: Model the orchestration as a single BLoC/Cubit state machine with explicit states (Loading, Loaded, Error) and ensure validation is always run atomically after mapping, never in parallel. Write integration tests that simulate network failure at each step of the chain.
Contingency: If a partial failure state reaches production, detect it via the missing validation summary field in the preview model and show a full-screen error state rather than an incomplete preview, prompting the coordinator to retry.