// lib/models/notification_model.dart import '../config/enum/action_enum.dart'; import '../config/enum/notification_status_enum.dart'; class NotificationModel { final int? id; final int senderId; final int receiverId; final ActionEnum action; final int? actionId; final String subject; final String content; final NotificationStatus status; final DateTime timestmp; NotificationModel({ this.id, required this.senderId, required this.receiverId, required this.action, this.actionId, required this.subject, required this.content, required this.status, required this.timestmp, }); factory NotificationModel.fromJson(Map json) { return NotificationModel( id: json['id'], senderId: json['sender'], receiverId: json['reciver'], action: ActionEnumExtension.fromString(json['action']), actionId: json['actionId'], subject: json['subject'], content: json['content'], status: NotificationStatusExtension.fromString(json['status']), timestmp: DateTime.parse(json['timestmp']), ); } Map toJson() { return { 'id': id, 'sender': senderId, 'reciver': receiverId, 'action': action.value, 'actionId': actionId, 'subject': subject, 'content': content, 'status': status.value, 'timestmp': timestmp.toIso8601String(), }; } /// Creates a copy of this NotificationModel with the given fields updated. NotificationModel copyWith({ int? id, int? senderId, int? receiverId, ActionEnum? action, int? actionId, String? subject, String? content, NotificationStatus? status, DateTime? timestmp, }) { return NotificationModel( id: id ?? this.id, senderId: senderId ?? this.senderId, receiverId: receiverId ?? this.receiverId, action: action ?? this.action, actionId: actionId ?? this.actionId, subject: subject ?? this.subject, content: content ?? this.content, status: status ?? this.status, timestmp: timestmp ?? this.timestmp, ); } }