TKK_E32230859/lib/app/models/notification_model.dart

70 lines
1.7 KiB
Dart

// lib/app/models/notification_model.dart
import 'package:cloud_firestore/cloud_firestore.dart';
class NotificationModel {
final String id;
final String patientId;
final String deviceId;
final String title;
final String message;
final bool isRead;
final DateTime createdAt;
NotificationModel({
required this.id,
required this.patientId,
required this.deviceId,
required this.title,
required this.message,
this.isRead = false,
required this.createdAt,
});
// From Firestore
factory NotificationModel.fromFirestore(DocumentSnapshot doc) {
final data = doc.data() as Map<String, dynamic>;
return NotificationModel(
id: doc.id,
patientId: data['patient_id'] ?? '',
deviceId: data['device_id'] ?? '',
title: data['title'] ?? '',
message: data['message'] ?? '',
isRead: data['is_read'] ?? false,
createdAt: data['created_at'] != null
? (data['created_at'] as Timestamp).toDate()
: DateTime.now(),
);
}
// To Firestore
Map<String, dynamic> toFirestore() {
return {
'patient_id': patientId,
'device_id': deviceId,
'title': title,
'message': message,
'is_read': isRead,
'created_at': Timestamp.fromDate(createdAt),
};
}
NotificationModel copyWith({
String? id,
String? patientId,
String? deviceId,
String? title,
String? message,
bool? isRead,
DateTime? createdAt,
}) {
return NotificationModel(
id: id ?? this.id,
patientId: patientId ?? this.patientId,
deviceId: deviceId ?? this.deviceId,
title: title ?? this.title,
message: message ?? this.message,
isRead: isRead ?? this.isRead,
createdAt: createdAt ?? this.createdAt,
);
}
}