|
| 1 | +import 'package:equatable/equatable.dart'; |
| 2 | +import 'package:ht_shared/src/models/core/content_type.dart'; |
| 3 | +import 'package:ht_shared/src/models/feed_decorators/suggested_content_display_type.dart'; |
| 4 | +import 'package:ht_shared/src/models/feed_extras/feed_template_types.dart'; |
| 5 | +import 'package:json_annotation/json_annotation.dart'; |
| 6 | + |
| 7 | +part 'suggested_content_template.g.dart'; |
| 8 | + |
| 9 | +/// {@template suggested_content_template} |
| 10 | +/// Defines the static content and configuration for a suggestion block. |
| 11 | +/// The 'type' of an instance should match a [SuggestionTemplateType] value. |
| 12 | +/// {@endtemplate} |
| 13 | +@JsonSerializable(explicitToJson: true) |
| 14 | +class SuggestedContentTemplate extends Equatable { |
| 15 | + /// {@macro suggested_content_template} |
| 16 | + const SuggestedContentTemplate({ |
| 17 | + required this.type, |
| 18 | + required this.displayType, |
| 19 | + required this.suggestedContentType, |
| 20 | + this.title, |
| 21 | + this.description, |
| 22 | + this.maxItemsToDisplay, |
| 23 | + this.fetchCriteria, |
| 24 | + }); |
| 25 | + |
| 26 | + /// Creates a [SuggestedContentTemplate] from JSON data. |
| 27 | + factory SuggestedContentTemplate.fromJson(Map<String, dynamic> json) => |
| 28 | + _$SuggestedContentTemplateFromJson(json); |
| 29 | + |
| 30 | + /// The type of suggestion template, matching a [SuggestionTemplateType] value. |
| 31 | + final SuggestionTemplateType type; |
| 32 | + |
| 33 | + /// An optional title for the suggestion block (e.g., "You might like..."). |
| 34 | + final String? title; |
| 35 | + |
| 36 | + /// An optional description for the suggestion block. |
| 37 | + final String? description; |
| 38 | + |
| 39 | + /// The visual presentation or layout style for this suggestion block. |
| 40 | + final SuggestedContentDisplayType displayType; |
| 41 | + |
| 42 | + /// Defines what kind of primary content this suggestion block will contain |
| 43 | + /// (e.g., if suggesting categories, this would be [ContentType.category]). |
| 44 | + final ContentType suggestedContentType; |
| 45 | + |
| 46 | + /// Maximum number of items to display within this suggestion block. |
| 47 | + final int? maxItemsToDisplay; |
| 48 | + |
| 49 | + /// Criteria for fetching dynamic items, e.g., "popular", "newest". |
| 50 | + /// This is a simple string; the decorator will interpret it. |
| 51 | + final String? fetchCriteria; |
| 52 | + |
| 53 | + /// Converts this [SuggestedContentTemplate] instance to JSON data. |
| 54 | + Map<String, dynamic> toJson() => _$SuggestedContentTemplateToJson(this); |
| 55 | + |
| 56 | + @override |
| 57 | + List<Object?> get props => [ |
| 58 | + type, |
| 59 | + title, |
| 60 | + description, |
| 61 | + displayType, |
| 62 | + suggestedContentType, |
| 63 | + maxItemsToDisplay, |
| 64 | + fetchCriteria, |
| 65 | + ]; |
| 66 | +} |
0 commit comments