96 lines
2.8 KiB
Dart
96 lines
2.8 KiB
Dart
library notification_model;
|
|
|
|
import 'package:equatable/equatable.dart';
|
|
|
|
/// Modèle de données pour une notification
|
|
/// Aligné avec NotificationDTO côté backend
|
|
class NotificationModel extends Equatable {
|
|
final String id;
|
|
final String typeNotification;
|
|
final String? priorite;
|
|
final String? statut;
|
|
final String? sujet;
|
|
final String? corps;
|
|
final DateTime? dateEnvoiPrevue;
|
|
final DateTime? dateEnvoi;
|
|
final DateTime? dateLecture;
|
|
final String? donneesAdditionnelles;
|
|
final String? membreId;
|
|
final String? organisationId;
|
|
|
|
const NotificationModel({
|
|
required this.id,
|
|
required this.typeNotification,
|
|
this.priorite,
|
|
this.statut,
|
|
this.sujet,
|
|
this.corps,
|
|
this.dateEnvoiPrevue,
|
|
this.dateEnvoi,
|
|
this.dateLecture,
|
|
this.donneesAdditionnelles,
|
|
this.membreId,
|
|
this.organisationId,
|
|
});
|
|
|
|
bool get estLue => statut == 'LUE' || dateLecture != null;
|
|
|
|
String get typeAffichage {
|
|
switch (typeNotification) {
|
|
case 'EVENEMENT':
|
|
return 'Événements';
|
|
case 'MEMBRE':
|
|
return 'Membres';
|
|
case 'ORGANISATION':
|
|
return 'Organisations';
|
|
case 'COTISATION':
|
|
return 'Cotisations';
|
|
case 'ADHESION':
|
|
return 'Adhésions';
|
|
default:
|
|
return 'Système';
|
|
}
|
|
}
|
|
|
|
factory NotificationModel.fromJson(Map<String, dynamic> json) {
|
|
return NotificationModel(
|
|
id: json['id']?.toString() ?? '',
|
|
typeNotification: json['typeNotification']?.toString() ?? 'SYSTEME',
|
|
priorite: json['priorite']?.toString(),
|
|
statut: json['statut']?.toString(),
|
|
sujet: json['sujet']?.toString(),
|
|
corps: json['corps']?.toString(),
|
|
dateEnvoiPrevue: json['dateEnvoiPrevue'] != null
|
|
? DateTime.tryParse(json['dateEnvoiPrevue'].toString())
|
|
: null,
|
|
dateEnvoi: json['dateEnvoi'] != null
|
|
? DateTime.tryParse(json['dateEnvoi'].toString())
|
|
: null,
|
|
dateLecture: json['dateLecture'] != null
|
|
? DateTime.tryParse(json['dateLecture'].toString())
|
|
: null,
|
|
donneesAdditionnelles: json['donneesAdditionnelles']?.toString(),
|
|
membreId: json['membreId']?.toString(),
|
|
organisationId: json['organisationId']?.toString(),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'id': id,
|
|
'typeNotification': typeNotification,
|
|
'priorite': priorite,
|
|
'statut': statut,
|
|
'sujet': sujet,
|
|
'corps': corps,
|
|
'dateEnvoiPrevue': dateEnvoiPrevue?.toIso8601String(),
|
|
'dateEnvoi': dateEnvoi?.toIso8601String(),
|
|
'dateLecture': dateLecture?.toIso8601String(),
|
|
'donneesAdditionnelles': donneesAdditionnelles,
|
|
'membreId': membreId,
|
|
'organisationId': organisationId,
|
|
};
|
|
|
|
@override
|
|
List<Object?> get props => [id, typeNotification, statut, dateLecture];
|
|
}
|