import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:tatlock_ui/features/front_hall/domain/entities/quick_link.dart'; part 'quick_link_model.freezed.dart'; part 'quick_link_model.g.dart'; /// Quick link data model matching Core API dashboard/quick-links endpoint. /// /// Field mapping: /// - title (API) ↔ name (Flutter entity) /// - icon (API) ↔ iconName (Flutter entity) /// - position (API) ↔ sortOrder (Flutter entity) /// - is_visible (API) ↔ isActive (Flutter entity) /// - link_type (API) ↔ type (Flutter entity) @freezed sealed class QuickLinkModel with _$QuickLinkModel { const factory QuickLinkModel({ @Default(0) int id, required String title, required String url, String? icon, String? description, String? category, @Default(0) int position, @JsonKey(name: 'is_visible') @Default(true) bool isVisible, @JsonKey(name: 'link_type') @Default('iframe') String linkType, String? color, @JsonKey(name: 'background_color') String? backgroundColor, }) = _QuickLinkModel; const QuickLinkModel._(); factory QuickLinkModel.fromJson(Map json) => _$QuickLinkModelFromJson(json); /// Converts to domain entity. QuickLink toEntity() { return QuickLink( id: id.toString(), name: title, url: url, iconName: icon ?? 'link', category: category, type: _parseQuickLinkType(linkType), sortOrder: position, isActive: isVisible, ); } /// Creates model from domain entity. factory QuickLinkModel.fromEntity(QuickLink entity) { return QuickLinkModel( id: int.tryParse(entity.id) ?? 0, title: entity.name, url: entity.url, icon: entity.iconName, category: entity.category, position: entity.sortOrder, isVisible: entity.isActive, linkType: _formatQuickLinkType(entity.type), ); } } /// Parses API link_type string to QuickLinkType enum. QuickLinkType _parseQuickLinkType(String linkType) { return switch (linkType) { 'new_tab' => QuickLinkType.newTab, _ => QuickLinkType.iframe, }; } /// Formats QuickLinkType enum to API link_type string. String _formatQuickLinkType(QuickLinkType type) { return switch (type) { QuickLinkType.newTab => 'new_tab', QuickLinkType.iframe => 'iframe', }; }