Files
eatvio_app/lib/features/notifications/models/notification_model.dart
2025-05-22 22:00:01 +07:00

285 lines
9.2 KiB
Dart

sealed class BaseNotificationModel {
abstract final NotificationType type;
}
class PlanSubscriptionStartedToAuthorNotification implements BaseNotificationModel {
@override
final NotificationType type;
final String planName;
final String customerName;
final String chatId;
PlanSubscriptionStartedToAuthorNotification({
required this.type,
required this.planName,
required this.customerName,
required this.chatId,
});
factory PlanSubscriptionStartedToAuthorNotification.fromJson(Map<String, dynamic> json, NotificationType type) {
return PlanSubscriptionStartedToAuthorNotification(
type: type,
planName: json['plan_name'],
customerName: json['user_name'],
chatId: json['chat_id'],
);
}
}
class PlanSubscriptionCanceledToAuthorNotification implements BaseNotificationModel {
@override
final NotificationType type;
final String planName;
final String customerName;
PlanSubscriptionCanceledToAuthorNotification({
required this.type,
required this.planName,
required this.customerName,
});
factory PlanSubscriptionCanceledToAuthorNotification.fromJson(Map<String, dynamic> json, NotificationType type) {
return PlanSubscriptionCanceledToAuthorNotification(
type: type,
planName: json['plan_name'],
customerName: json['user_name'],
);
}
}
class ChosenPlanStartedToClientNotification implements BaseNotificationModel {
@override
final NotificationType type;
final String planName;
final int planId;
ChosenPlanStartedToClientNotification({
required this.type,
required this.planName,
required this.planId,
});
factory ChosenPlanStartedToClientNotification.fromJson(Map<String, dynamic> json, NotificationType type) {
return ChosenPlanStartedToClientNotification(
type: type,
planName: json['plan_name'],
planId: json['plan_id'],
);
}
}
class ChosenPlanTomorrowReminderToClientNotification implements BaseNotificationModel {
@override
final NotificationType type;
final String planName;
ChosenPlanTomorrowReminderToClientNotification({
required this.type,
required this.planName,
});
factory ChosenPlanTomorrowReminderToClientNotification.fromJson(Map<String, dynamic> json, NotificationType type) {
return ChosenPlanTomorrowReminderToClientNotification(
type: type,
planName: json['plan_name'],
);
}
}
class DiaryReminderNotification implements BaseNotificationModel {
@override
final NotificationType type;
DiaryReminderNotification({required this.type});
factory DiaryReminderNotification.fromJson(Map<String, dynamic> json, NotificationType type) {
return DiaryReminderNotification(
type: type,
);
}
}
class ConsultantLeftCommentNotification implements BaseNotificationModel {
@override
final NotificationType type;
final DateTime date;
ConsultantLeftCommentNotification({
required this.type,
required this.date,
});
factory ConsultantLeftCommentNotification.fromJson(Map<String, dynamic> json, NotificationType type) {
return ConsultantLeftCommentNotification(type: type, date: json['diary_date']);
}
}
class PersonalizedDietIsDefinedNotification implements BaseNotificationModel {
@override
final NotificationType type;
PersonalizedDietIsDefinedNotification({required this.type});
factory PersonalizedDietIsDefinedNotification.fromJson(Map<String, dynamic> json, NotificationType type) {
return PersonalizedDietIsDefinedNotification(
type: type,
);
}
}
class ChosenPlanFinishedToClientNotification implements BaseNotificationModel {
@override
final NotificationType type;
final String planName;
ChosenPlanFinishedToClientNotification({
required this.type,
required this.planName,
});
factory ChosenPlanFinishedToClientNotification.fromJson(Map<String, dynamic> json, NotificationType type) {
return ChosenPlanFinishedToClientNotification(type: type, planName: json['plan_name']);
}
}
class PlanSubscriptionCanceledToCustomerNotification implements BaseNotificationModel {
@override
final NotificationType type;
final String planName;
PlanSubscriptionCanceledToCustomerNotification({
required this.type,
required this.planName,
});
factory PlanSubscriptionCanceledToCustomerNotification.fromJson(Map<String, dynamic> json, NotificationType type) {
return PlanSubscriptionCanceledToCustomerNotification(
type: type,
planName: json['plan_name'],
);
}
}
class ChosenPlanStartedToConsultantNotification implements BaseNotificationModel {
@override
final NotificationType type;
final String planName;
final String customerName;
ChosenPlanStartedToConsultantNotification({
required this.type,
required this.planName,
required this.customerName,
});
factory ChosenPlanStartedToConsultantNotification.fromJson(Map<String, dynamic> json, NotificationType type) {
return ChosenPlanStartedToConsultantNotification(
type: type,
planName: json['plan_name'],
customerName: json['client_name'],
);
}
}
class ChosenPlanTomorrowReminderToConsultantNotification implements BaseNotificationModel {
@override
final NotificationType type;
final String planName;
final String customerName;
ChosenPlanTomorrowReminderToConsultantNotification({
required this.type,
required this.planName,
required this.customerName,
});
factory ChosenPlanTomorrowReminderToConsultantNotification.fromJson(Map<String, dynamic> json, NotificationType type) {
return ChosenPlanTomorrowReminderToConsultantNotification(
type: type,
planName: json['plan_name'],
customerName: json['client_name'],
);
}
}
class PlanSubscriptionPaidToAuthorNotification implements BaseNotificationModel {
@override
final NotificationType type;
final String planName;
final String customerName;
PlanSubscriptionPaidToAuthorNotification({
required this.type,
required this.planName,
required this.customerName,
});
factory PlanSubscriptionPaidToAuthorNotification.fromJson(Map<String, dynamic> json, NotificationType type) {
return PlanSubscriptionPaidToAuthorNotification(
type: type,
planName: json['plan_name'],
customerName: json['user_name'],
);
}
}
class ChosenPlanFinishedToConsultantNotification implements BaseNotificationModel {
@override
final NotificationType type;
final String planName;
final String customerName;
final int planId;
ChosenPlanFinishedToConsultantNotification({
required this.type,
required this.planName,
required this.customerName,
required this.planId,
});
factory ChosenPlanFinishedToConsultantNotification.fromJson(Map<String, dynamic> json, NotificationType type) {
return ChosenPlanFinishedToConsultantNotification(
type: type,
planName: json['plan_name'],
customerName: json['client_name'],
planId: json['plan_id'],
);
}
}
class UnknownNotification implements BaseNotificationModel {
@override
final NotificationType type;
UnknownNotification({
required this.type,
});
}
enum NotificationType {
planSubscriptionStartedToAuthor,
planSubscriptionCanceledToAuthor,
chosenPlanStartedToClientNotification,
chosenPlanTomorrowReminderToClientNotification,
diaryReminderNotification,
consultantLeftComment,
personalizedDietIsDefined,
chosenPlanFinishedToClient,
planSubscriptionCanceledToCustomer,
chosenPlanStartedToConsultantNotification,
chosenPlanTomorrowReminderToConsultantNotification,
planSubscriptionPaidToAuthor,
chosenPlanFinishedToConsultant,
unknown;
static NotificationType getTypeFromString(String type) => switch (type) {
'App\\Notifications\\Plan\\PlanSubscriptionStartedToAuthor' => NotificationType.planSubscriptionStartedToAuthor,
'App\\Notifications\\Plan\\PlanSubscriptionCanceledToAuthor' => NotificationType.planSubscriptionCanceledToAuthor,
'App\\Notifications\\Plan\\ChosenPlanStartedToClientNotification' => NotificationType.chosenPlanStartedToClientNotification,
'App\\Notifications\\Plan\\ChosenPlanTomorrowReminderToClientNotification' => NotificationType.chosenPlanStartedToClientNotification,
'App\\Notifications\\DiaryReminderNotification' => NotificationType.diaryReminderNotification,
'App\\Notifications\\Plan\\ConsultantLeftComment' => NotificationType.consultantLeftComment,
'App\\Notifications\\Plan\\PersonalizedDietIsDefined' => NotificationType.personalizedDietIsDefined,
'App\\Notifications\\Plan\\ChosenPlanFinishedToClient' => NotificationType.chosenPlanFinishedToClient,
'App\\Notifications\\Plan\\PlanSubscriptionCanceledToCustomer' => NotificationType.planSubscriptionCanceledToCustomer,
'App\\Notifications\\Plan\\ChosenPlanStartedToConsultantNotification' => NotificationType.chosenPlanStartedToConsultantNotification,
'App\\Notifications\\Plan\\ChosenPlanTomorrowReminderToConsultantNotification' => NotificationType.chosenPlanTomorrowReminderToConsultantNotification,
'App\\Notifications\\Plan\\PlanSubscriptionPaidToAuthor' => NotificationType.planSubscriptionPaidToAuthor,
'App\\Notifications\\Plan\\ChosenPlanFinishedToConsultant' => NotificationType.chosenPlanFinishedToConsultant,
_ => NotificationType.unknown,
};
}