Benefit Calculation Result Model
Component Detail
Description
Immutable value object and associated serialization logic for a completed benefit calculation. Stores all computed metrics and the input parameters used, enabling result reconstruction for sharing without recalculation.
benefit-calculation-result-model
Summaries
The Benefit Calculation Result Model is the foundational data contract that makes computed impact figures portable and reproducible across the application. By storing both the calculated metrics and the exact input parameters used to produce them, the model ensures that a result shared externally can be reconstructed and verified at any time, which is essential for audit trails and funder reporting. Its immutable design means that once a calculation is confirmed, the figures cannot be accidentally mutated as they flow through the sharing and display pipeline, protecting the organisation from inadvertently publishing inaccurate impact data and maintaining the trust of beneficiaries and grant bodies alike.
The Benefit Calculation Result Model is a pure data definition with no network or storage dependencies, making it the lowest-risk deliverable in the calculator feature set and an ideal first implementation task that unblocks all consuming components. Its interface must be finalised before the calculation service, BLoC, results card, and share service can be implemented; treat it as a critical-path item for sprint planning. The toJson and fromJson methods require thorough unit testing with boundary values — particularly floating-point precision for currency and hour figures — to prevent rounding errors from appearing in shared outputs. Changes to this model's fields after consuming components are built will require coordinated updates across the entire calculator feature.
BenefitCalculationResult is an immutable value object holding typed double fields for hoursSaved, travelCostAvoided, and healthSystemOffset, plus the originating BenefitCalculationInput for full input traceability. Implement with freezed to automatically generate copyWith, equality, hashCode, and JSON serialization, or replicate manually if freezed is not a project dependency. The fromJson factory must handle null-safety gracefully for fields added in future schema versions to maintain backward compatibility with cached or shared payloads. This model is the single serialization boundary for the calculator feature — all persistence, sharing, and BLoC state diffing flows through it, so field naming must be stable and JSON keys should be explicitly annotated rather than relying on field name inference.
Responsibilities
- Define typed fields for all personal and societal benefit metrics
- Provide copyWith and equality for BLoC state comparison
- Serialize to/from JSON for share-payload construction
Interfaces
BenefitCalculationResult({required double hoursSaved, required double travelCostAvoided, required double healthSystemOffset, required BenefitCalculationInput input})
toJson() → Map<String, dynamic>
fromJson(Map<String, dynamic>) → BenefitCalculationResult
copyWith(...) → BenefitCalculationResult