You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
168 lines
5.4 KiB
Dart
168 lines
5.4 KiB
Dart
|
1 week ago
|
import 'package:test_sa/modules/notification_setting/models/notification_channel_model.dart';
|
||
|
|
|
||
|
|
class NotificationPreferenceResponse {
|
||
|
|
final List<NotificationTemplate>? data;
|
||
|
|
final int? totalRows;
|
||
|
|
final int? count;
|
||
|
|
final String? message;
|
||
|
|
final String? title;
|
||
|
|
final String? innerMessage;
|
||
|
|
final int? responseCode;
|
||
|
|
final bool? isSuccess;
|
||
|
|
|
||
|
|
NotificationPreferenceResponse({
|
||
|
|
this.data,
|
||
|
|
this.totalRows,
|
||
|
|
this.count,
|
||
|
|
this.message,
|
||
|
|
this.title,
|
||
|
|
this.innerMessage,
|
||
|
|
this.responseCode,
|
||
|
|
this.isSuccess,
|
||
|
|
});
|
||
|
|
|
||
|
|
factory NotificationPreferenceResponse.fromJson(Map<String, dynamic> json) {
|
||
|
|
return NotificationPreferenceResponse(
|
||
|
|
data: json['data'] != null
|
||
|
|
? (json['data'] as List).map((e) => NotificationTemplate.fromJson(e)).toList()
|
||
|
|
: null,
|
||
|
|
totalRows: json['totalRows'],
|
||
|
|
count: json['count'],
|
||
|
|
message: json['message'],
|
||
|
|
title: json['title'],
|
||
|
|
innerMessage: json['innerMessage'],
|
||
|
|
responseCode: json['responseCode'],
|
||
|
|
isSuccess: json['isSuccess'],
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
Map<String, dynamic> toJson() {
|
||
|
|
return {
|
||
|
|
'data': data?.map((e) => e.toJson()).toList(),
|
||
|
|
'totalRows': totalRows,
|
||
|
|
'count': count,
|
||
|
|
'message': message,
|
||
|
|
'title': title,
|
||
|
|
'innerMessage': innerMessage,
|
||
|
|
'responseCode': responseCode,
|
||
|
|
'isSuccess': isSuccess,
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class NotificationTemplate {
|
||
|
|
final int? notificationTemplateId;
|
||
|
|
final String? templateName;
|
||
|
|
final String? moduleName;
|
||
|
|
final String? subModuleName;
|
||
|
|
final bool? mandatory;
|
||
|
|
final bool? isDisabled;
|
||
|
|
final String? channelNames;
|
||
|
|
final bool? isCustom;
|
||
|
|
final List<NotificationChannel>? templateChannels;
|
||
|
|
final List<NotificationChannel>? preferenceChannels;
|
||
|
|
|
||
|
|
// Local state for UI tracking
|
||
|
|
bool isModified;
|
||
|
|
List<int> selectedChannelIds;
|
||
|
|
|
||
|
|
NotificationTemplate({
|
||
|
|
this.notificationTemplateId,
|
||
|
|
this.templateName,
|
||
|
|
this.moduleName,
|
||
|
|
this.subModuleName,
|
||
|
|
this.mandatory,
|
||
|
|
this.isDisabled,
|
||
|
|
this.channelNames,
|
||
|
|
this.isCustom,
|
||
|
|
this.templateChannels,
|
||
|
|
this.preferenceChannels,
|
||
|
|
this.isModified = false,
|
||
|
|
List<int>? selectedChannelIds,
|
||
|
|
}) : selectedChannelIds = selectedChannelIds ?? [];
|
||
|
|
|
||
|
|
factory NotificationTemplate.fromJson(Map<String, dynamic> json) {
|
||
|
|
final List<NotificationChannel>? templateChannelsList = json['templateChannels'] != null
|
||
|
|
? (json['templateChannels'] as List).map((e) => NotificationChannel.fromJson(e)).toList()
|
||
|
|
: null;
|
||
|
|
|
||
|
|
final List<NotificationChannel>? preferenceChannelsList = json['preferenceChannels'] != null
|
||
|
|
? (json['preferenceChannels'] as List).map((e) => NotificationChannel.fromJson(e)).toList()
|
||
|
|
: null;
|
||
|
|
|
||
|
|
// Initialize selectedChannelIds from preferenceChannels if available, otherwise from templateChannels
|
||
|
|
List<int> initialSelectedIds = [];
|
||
|
|
if (preferenceChannelsList != null && preferenceChannelsList.isNotEmpty) {
|
||
|
|
initialSelectedIds = preferenceChannelsList
|
||
|
|
.where((e) => e.id != null)
|
||
|
|
.map((e) => e.id!)
|
||
|
|
.toList();
|
||
|
|
} else if (templateChannelsList != null && templateChannelsList.isNotEmpty) {
|
||
|
|
initialSelectedIds = templateChannelsList
|
||
|
|
.where((e) => e.id != null)
|
||
|
|
.map((e) => e.id!)
|
||
|
|
.toList();
|
||
|
|
}
|
||
|
|
|
||
|
|
return NotificationTemplate(
|
||
|
|
notificationTemplateId: json['notificationTemplateId'],
|
||
|
|
templateName: json['templateName'],
|
||
|
|
moduleName: json['moduleName'],
|
||
|
|
subModuleName: json['subModuleName'],
|
||
|
|
mandatory: json['mandatory'],
|
||
|
|
isDisabled: json['isDisabled'],
|
||
|
|
channelNames: json['channelNames'],
|
||
|
|
isCustom: json['isCustom'],
|
||
|
|
templateChannels: templateChannelsList,
|
||
|
|
preferenceChannels: preferenceChannelsList,
|
||
|
|
selectedChannelIds: initialSelectedIds,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
Map<String, dynamic> toJson() {
|
||
|
|
return {
|
||
|
|
'notificationTemplateId': notificationTemplateId,
|
||
|
|
'templateName': templateName,
|
||
|
|
'moduleName': moduleName,
|
||
|
|
'subModuleName': subModuleName,
|
||
|
|
'mandatory': mandatory,
|
||
|
|
'isDisabled': isDisabled,
|
||
|
|
'channelNames': channelNames,
|
||
|
|
'isCustom': isCustom,
|
||
|
|
'templateChannels': templateChannels?.map((e) => e.toJson()).toList(),
|
||
|
|
'preferenceChannels': preferenceChannels?.map((e) => e.toJson()).toList(),
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
// Create a copy with modified values
|
||
|
|
NotificationTemplate copyWith({
|
||
|
|
int? notificationTemplateId,
|
||
|
|
String? templateName,
|
||
|
|
String? moduleName,
|
||
|
|
String? subModuleName,
|
||
|
|
bool? mandatory,
|
||
|
|
bool? isDisabled,
|
||
|
|
String? channelNames,
|
||
|
|
bool? isCustom,
|
||
|
|
List<NotificationChannel>? templateChannels,
|
||
|
|
List<NotificationChannel>? preferenceChannels,
|
||
|
|
bool? isModified,
|
||
|
|
List<int>? selectedChannelIds,
|
||
|
|
}) {
|
||
|
|
return NotificationTemplate(
|
||
|
|
notificationTemplateId: notificationTemplateId ?? this.notificationTemplateId,
|
||
|
|
templateName: templateName ?? this.templateName,
|
||
|
|
moduleName: moduleName ?? this.moduleName,
|
||
|
|
subModuleName: subModuleName ?? this.subModuleName,
|
||
|
|
mandatory: mandatory ?? this.mandatory,
|
||
|
|
isDisabled: isDisabled ?? this.isDisabled,
|
||
|
|
channelNames: channelNames ?? this.channelNames,
|
||
|
|
isCustom: isCustom ?? this.isCustom,
|
||
|
|
templateChannels: templateChannels ?? this.templateChannels,
|
||
|
|
preferenceChannels: preferenceChannels ?? this.preferenceChannels,
|
||
|
|
isModified: isModified ?? this.isModified,
|
||
|
|
selectedChannelIds: selectedChannelIds ?? this.selectedChannelIds,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|