Implement Duplicate Queue Repository
epic-duplicate-activity-detection-state-management-task-002 — Create the DuplicateQueueRepository data layer for coordinator deduplication queue operations. Implement CRUD methods for queued duplicate records, status transitions (pending, reviewed, resolved, dismissed), and batch query support for coordinator queue screen pagination.
Acceptance Criteria
Technical Requirements
Implementation Notes
Model DuplicateQueueStatus as a Dart enum with a `fromString` factory that throws on unknown values — never use raw strings from the database as enum values without validation. The DuplicateQueuePage value object should carry both `items` and `totalCount` so the UI can render a progress indicator (e.g., '12 of 47 resolved'). For the coordinator queue, NHF's structure of 12 landsforeninger × 9 regioner × 1,400 chapters means a coordinator's scope may span multiple chapters — the `coordinator_scope` should be stored as a list of chapter IDs, not a single FK. Pitfall: offset-based pagination becomes inconsistent if items are inserted between page fetches (coordinator sees duplicates or gaps).
Consider cursor-based pagination using `created_at + id` composite cursor for production stability. If Supabase Realtime is scoped into this task, use `supabase.channel()` with a filter on `coordinator_id` to avoid broadcasting all queue changes to all clients.
Testing Requirements
Unit tests using flutter_test with mocked Supabase client. Test scenarios: (1) first page returned with correct count and hasNextPage=true; (2) last page returns hasNextPage=false; (3) status filter returns only matching items; (4) valid status transition succeeds; (5) invalid transition (e.g., resolved→pending) throws DuplicateQueueTransitionException; (6) enqueue creates item in pending status with correct coordinator assignment; (7) RLS violation (coordinator accessing another chapter's queue) surfaces as typed PermissionException. Integration tests against local Supabase: seed 25 queue items across 3 coordinators, verify pagination returns correct subsets per coordinator. Test that Supabase Realtime subscription (if implemented) delivers a new item event within 2 seconds of insertion.
For bulk registration with many participants, running duplicate checks sequentially before surfacing the consolidated summary could introduce a multi-second delay as each peer mentor is checked individually against the RPC. This degrades the bulk submission UX significantly.
Mitigation & Contingency
Mitigation: Issue all duplicate check RPC calls concurrently using Dart's `Future.wait` or a bounded parallel executor (max 5 concurrent calls to avoid Supabase rate limits). The BLoC collects all results and emits a single BulkDuplicateSummary state with the consolidated list.
Contingency: If concurrent RPC calls hit Supabase connection limits or rate limits, implement a batched sequential approach with a progress indicator showing 'Checking participant N of M' so the coordinator understands the delay is expected and bounded.
In proxy registration, the peer mentor's ID must be used as the duplicate check parameter, not the coordinator's ID. If the proxy context is not correctly threaded through the BLoC and service layer, duplicate checks will silently run against the wrong person, missing actual duplicates.
Mitigation & Contingency
Mitigation: Define a `SubmissionContext` model that carries the effective `peer_mentor_id` (distinct from `submitter_id`) and pass it explicitly through the BLoC event payload. The DuplicateDetectionService always reads peer_mentor_id from SubmissionContext, never from the authenticated user session.
Contingency: If SubmissionContext threading proves difficult to retrofit into the existing proxy registration BLoC, add an assertion in DuplicateDetectionService that throws a descriptive error when peer_mentor_id is null or matches the coordinator's own ID in a proxy context, making the bug immediately visible in testing.