1+ import 'package:equatable/equatable.dart' ;
12import 'package:ht_shared/src/models/feed/engagement_content_type.dart' ;
23import 'package:ht_shared/src/models/feed/feed_item.dart' ;
3- import 'package:ht_shared/src/models/feed/feed_item_action.dart'
4- show FeedItemAction, feedItemActionFromJson, feedItemActionToJson;
5- import 'package:json_annotation/json_annotation.dart' ;
4+ import 'package:ht_shared/src/models/feed/feed_item_action.dart' ;
5+ import 'package:ht_shared/src/utils/json_converters.dart' ;
66import 'package:uuid/uuid.dart' ;
77
8- part 'engagement_content.g.dart' ;
9-
108/// {@template engagement_content}
119/// A generic model for in-feed calls-to-action or engagement prompts.
1210///
1311/// This item encourages user interaction, such as signing up, upgrading,
1412/// or providing feedback. The [engagementContentType] specifies the nature
1513/// of the call-to-action.
1614/// {@endtemplate}
17- @JsonSerializable (explicitToJson: true , includeIfNull: false )
1815class EngagementContent extends FeedItem {
1916 /// {@macro engagement_content}
2017 EngagementContent ({
2118 required this .title,
2219 required this .engagementContentType,
23- required super .action,
20+ required super .action, // Refactored to super.action
2421 this .description,
2522 this .callToActionText,
2623 this .callToActionUrl,
2724 String ? id,
2825 }) : id = id ?? const Uuid ().v4 (),
29- super (type: 'engagement_content' );
26+ super (type: 'engagement_content' ); // Removed action from super constructor
3027
3128 /// Factory method to create an [EngagementContent] instance from a JSON map.
32- factory EngagementContent .fromJson (Map <String , dynamic > json) =>
33- _$EngagementContentFromJson (json);
29+ factory EngagementContent .fromJson (Map <String , dynamic > json) {
30+ return EngagementContent (
31+ id: json['id' ] as String ? ,
32+ title: json['title' ] as String ,
33+ description: json['description' ] as String ? ,
34+ engagementContentType: engagementContentTypeFromJson (
35+ json['engagementContentType' ] as String ,
36+ ),
37+ callToActionText: json['callToActionText' ] as String ? ,
38+ callToActionUrl: json['callToActionUrl' ] as String ? ,
39+ action: FeedItemAction .fromJson (json['action' ] as Map <String , dynamic >),
40+ );
41+ }
3442
3543 /// Unique identifier for the engagement content.
3644 final String id;
@@ -50,14 +58,22 @@ class EngagementContent extends FeedItem {
5058 /// The URL to navigate to when the call-to-action is triggered.
5159 final String ? callToActionUrl;
5260
53- /// The action to be performed when this feed item is interacted with.
54- @JsonKey (fromJson: feedItemActionFromJson, toJson: feedItemActionToJson)
55- @override
56- late final FeedItemAction action;
57-
5861 /// Converts this [EngagementContent] instance to a JSON map.
5962 @override
60- Map <String , dynamic > toJson () => _$EngagementContentToJson (this );
63+ Map <String , dynamic > toJson () {
64+ final Map <String , dynamic > json = {
65+ 'id' : id,
66+ 'title' : title,
67+ 'description' : description,
68+ 'engagementContentType' :
69+ engagementContentTypeToJson (engagementContentType),
70+ 'callToActionText' : callToActionText,
71+ 'callToActionUrl' : callToActionUrl,
72+ 'action' : action.toJson (),
73+ 'type' : type, // Inherited from FeedItem
74+ };
75+ return json..removeWhere ((key, value) => value == null );
76+ }
6177
6278 @override
6379 List <Object ?> get props => [
0 commit comments