Implement ActivityTypeService with metadata validation
epic-activity-type-configuration-business-logic-task-004 — Build ActivityTypeService enforcing org-scoped business rules. Implement getActiveTypes(orgId), createActivityType, updateActivityType, and deactivateActivityType. Add metadata flag validation: if triggersReimbursementWorkflow is true, isTravelExpenseEligible must also be true for orgs with strict reimbursement config. Coordinate cache invalidation via ActivityTypeCacheProvider after every mutation. Map database rows to ActivityType domain objects.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 3 - 413 tasks
Can start after Tier 2 completes
Implementation Notes
Place in lib/features/activity_type/domain/services/activity_type_service.dart. Inject IActivityTypeRepository and ActivityTypeCacheNotifier via constructor for testability. The org strictReimbursementConfig flag should come from an OrganizationConfigProvider (or equivalent) injected into the service — do not hard-code which orgs are strict. The validation logic for triggersReimbursementWorkflow/isTravelExpenseEligible should be extracted into a private _validateMetadataFlags() method to keep mutation methods readable.
Always invalidate cache AFTER a successful mutation (not before) — if the mutation fails, the cache remains valid. Use Result
Testing Requirements
Unit tests using flutter_test with mocked IActivityTypeRepository and mocked ActivityTypeCacheNotifier: (1) getActiveTypes delegates to cache provider, (2) createActivityType with valid data calls repository.create and then cache.invalidate, (3) updateActivityType with valid data calls repository.update and then cache.invalidate, (4) deactivateActivityType calls repository.softDelete and cache.invalidate, (5) triggersReimbursementWorkflow validation: strict org + incompatible flags throws ActivityTypeValidationException, (6) triggersReimbursementWorkflow validation: non-strict org + same flags succeeds, (7) repository.create failure propagates RepositoryException without calling cache.invalidate, (8) all mutations return correct ActivityType object. Test matrix covers all flag combinations for metadata validation.
Metadata flag combination rules differ between organisations (e.g., Blindeforbundet honorarium thresholds, HLF mutual exclusion of km and transit). Encoding these as generic service-level validation may be insufficient, forcing organisation-specific branching inside the service that becomes unmaintainable as new organisations are onboarded.
Mitigation & Contingency
Mitigation: Model flag validation as a pure function that accepts an ActivityTypeMetadata object and an org configuration record, making org-specific rules data-driven rather than hardcoded. Establish the validation contract in the foundation epic so the service just delegates to the validator.
Contingency: Defer complex cross-flag validation to a lightweight edge function that can be updated without a mobile app release, accepting that initial validation in the mobile service layer is permissive and corrected server-side.
Blindeforbundet users rely on VoiceOver and JAWS. If the selection screen is built with non-semantic widgets that fail accessibility audit late in the sprint, a significant rework of the widget tree may be required, blocking the registration wizard integration.
Mitigation & Contingency
Mitigation: Build the selection screen against the project's established accessibility design tokens and semantics wrapper conventions from the start. Run Flutter's semantic tree inspector and a manual VoiceOver pass before marking any widget task complete.
Contingency: Wrap all tappable items in the project's SemanticsWrapperWidget and schedule a dedicated accessibility review session with a screen reader user from Blindeforbundet before the epic is closed.