Integrate AutoApprovalEvaluator pre-persistence status resolution
epic-mileage-reimbursement-entry-claim-orchestration-task-004 — Wire the synchronous AutoApprovalEvaluator call into submitClaim() so that ClaimStatus is resolved before any persistence occurs. Ensure below-threshold claims with no additional expenses receive silent-auto-approved status. Claims exceeding the threshold or carrying extra expenses receive pending-review status. No coordinator notification is dispatched for silent approvals.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 3 - 413 tasks
Can start after Tier 2 completes
Implementation Notes
AutoApprovalEvaluator should be implemented as a pure function class: `ClaimStatus evaluate(MileageClaim claim)`. The boundary condition for threshold (at exactly 50km) must be `>=` for pending review, not `>`, matching HLF's documented rule that automatic approval applies only below threshold. The no-notification requirement for silent approvals is critical: do NOT trigger any notification service, Supabase edge function, or push mechanism from within submitClaim(). If the coordinator notification system needs to be aware of pending-review claims, it should subscribe to database changes (e.g., a Supabase Realtime listener on the claims table) rather than being called inline.
Document this architectural decision with a comment in the service code. The fact that the threshold comes from the snapshot (not a re-fetch) is a deliberate TOCTOU protection: if an admin changes the threshold during a submission, the claim is evaluated under the rules that were in effect when the user started filling out the form.
Testing Requirements
Unit tests using `flutter_test`. Mock AutoApprovalEvaluator with `mocktail` or `mockito`. Required test cases: (1) distance 30km, threshold 50km, no expenses → silentAutoApproved; (2) distance 30km, threshold 50km, has expenses → pendingReview; (3) distance 50km, threshold 50km, no expenses → pendingReview (boundary: at-threshold is pending); (4) distance 75km, threshold 50km, no expenses → pendingReview; (5) distance 75km, threshold 50km, has expenses → pendingReview; (6) AutoApprovalEvaluator throws → submitClaim returns SubmissionFailure; (7) AutoApprovalEvaluator is NOT called when prior validation returned SubmissionFailure (verify mock was never called). Use `verifyNever()` for test case 7.
The auto-approval rule requires checking whether any additional expense lines are attached to the claim. The interface between the mileage claim and any co-submitted expense items is not fully defined within this feature's component scope. If the domain model does not include an explicit additionalExpenses collection, the evaluator cannot make a correct determination, which could auto-approve claims that should require manual review.
Mitigation & Contingency
Mitigation: Define the MileageClaim domain object interface with an explicit additionalExpenses: List field (nullable/empty for mileage-only claims) before implementing the service. Coordinate with the Expense Type Selection feature team to agree on the shared domain contract.
Contingency: If the cross-feature contract cannot be finalised before implementation, implement the evaluator to treat any non-null additionalExpenses list as requiring manual review and document the assumption for review during integration testing.
A peer mentor who taps the submit button multiple times rapidly (e.g. due to slow network) could cause MileageClaimService to be invoked concurrently, resulting in duplicate claim records being persisted with the same trip data.
Mitigation & Contingency
Mitigation: Implement a submission-in-progress guard in MileageClaimService using a BLoC/Cubit state flag that prevents re-entrant calls. The UI layer (implemented in Epic 4) will also disable the submit button during processing.
Contingency: Add a Supabase-level unique constraint or idempotency key on (user_id, origin, distance, submitted_at truncated to minute) to prevent duplicate rows reaching the database even if the application guard fails.