Neda/admin_panel/lib/models/notification_model.dart

79 lines
1.9 KiB
Dart

enum NotificationType { public, joinRequest }
extension NotificationTypeExtension on NotificationType {
String get label {
switch (this) {
case NotificationType.public:
return 'عمومی';
case NotificationType.joinRequest:
return 'درخواست عضویت';
}
}
String get apiValue {
switch (this) {
case NotificationType.public:
return 'public';
case NotificationType.joinRequest:
return 'join_request';
}
}
static NotificationType fromApi(String value) {
switch (value) {
case 'public':
return NotificationType.public;
case 'join_request':
return NotificationType.joinRequest;
default:
return NotificationType.public;
}
}
}
class NotificationModel {
final String id;
final String title;
final String? description;
final NotificationType type;
final bool? isAccepted;
final String receiverId;
final String? senderId;
final String? groupId;
const NotificationModel({
required this.id,
required this.title,
this.description,
required this.type,
this.isAccepted,
required this.receiverId,
this.senderId,
this.groupId,
});
factory NotificationModel.fromJson(Map<String, dynamic> json) {
return NotificationModel(
id: json['id'].toString(),
title: json['title'] as String,
description: json['description'] as String?,
type: NotificationTypeExtension.fromApi(json['type'] as String),
isAccepted: json['is_accepted'] as bool?,
receiverId: json['receiver_id'].toString(),
senderId: json['sender_id']?.toString(),
groupId: json['group_id']?.toString(),
);
}
Map<String, dynamic> toJson() => {
'id': id,
'title': title,
'description': description,
'type': type.apiValue,
'is_accepted': isAccepted,
'receiver_id': receiverId,
'sender_id': senderId,
'group_id': groupId,
};
}