import 'notification.m.dart';

typedef _ModelBuilder<T> = T Function(Map<String, dynamic> map);
class NotificationDecoder {
	NotificationDecoder._();

	static final _builders = _ModelBuilderCollection();

	static T decode<T>(Map<String, dynamic> map) {
		final type = decodeType(map);
		final builder = _builders.find(type);
		final model = builder.call(map) as T;
		return model;
	}
	static NotificationTypeEnum decodeType(Map<String, dynamic> map) {
		final typeInt = map['NotificationType'] as int;
		return NotificationTypeEnum.values[typeInt];
	}

	static void setup() {
		/** Register notification model builders here */
		_builders.add(NotificationTypeEnum.ApplyProbeApplicationSettingNotification,
				(map) => ApplyProbeApplicationSettingNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.SendCommandToDeviceNotification,
				(map) => SendCommandToDeviceNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.SendResultToClientNotification,
				(map) => SendResultToClientNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.SystemSettingSaveAndExitToClientNotification,
				(map) => SystemSettingSaveAndExitToClientNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.AnnouncementPublishNotification,
				(map) => AnnouncementNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.ChatMsgNotification,
				(map) => ChatMsgNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.ConnectionNotification,
				(map) => ConnectionNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.DeviceControlledParametersNotification,
				(map) => DeviceControlledParametersNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.DeviceDisconnectRemoteControlNotification,
				(map) => DeviceDisconnectRemoteControlNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.DeviceParametersNotification,
				(map) => DeviceParametersNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.DeviceRejectRemoteControlNotification,
				(map) => DeviceRejectRemoteControlNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.DisconnectNotification,
				(map) => DisconnectNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.ExamRecordsFinishedNotification,
				(map) => ExamRecordsFinishedNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.ExecuteResultNotification,
				(map) => ExecuteResultNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.ModifyDeviceMergedVideoSizeNotification,
				(map) => ModifyDeviceMergedVideoSizeNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.PasswordExpiredWarningNotification,
				(map) => PasswordExpiredWarningNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.ProgressBarNotification,
				(map) => ProgressBarNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.TokenReplacedNotification,
				(map) => TokenReplacedNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.VersionUpgradeNotification,
				(map) => UpgradeVersionNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.CloseLiveToDeviceNotification,
				(map) => CloseLiveToDeviceNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.ConnectStatusToClientNotification,
				(map) => ConnectStatusToClientNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.ConnectStatusToDeviceNotification,
				(map) => ConnectStatusToDeviceNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.DeviceLiveFinishedNotification,
				(map) => DeviceLiveFinishedNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.StartLiveToDeviceNotification,
				(map) => StartLiveToDeviceNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.CancelInvitingInLiveCourseNotification,
				(map) => CancelInvitingInLiveCourseNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.CancelLiveCourseNotification,
				(map) => CancelLiveCourseNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.ChangeShareInLiveCourseNotification,
				(map) => ChangeShareInLiveCourseNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.CloseLiveCourseNotification,
				(map) => CloseLiveCourseNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.CloseCourseHeartRateToDeviceNotification,
				(map) => CloseCourseHeartRateToDeviceNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.StartEducationHeartRateToDeviceNotification,
				(map) => StartEducationHeartRateToDeviceNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.CourcePaySuccessNotification,
				(map) => CourcePaySuccessNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.CourseEntryNotification,
				(map) => CourseEntryNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.CourseStatusNotification,
				(map) => CourseStatusNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.HeartRateJoinCoNotification,
				(map) => HeartRateJoinCourseNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.HeartRateLeaveCourseNotification,
				(map) => HeartRateLeaveCourseNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.InviteLiveCourseNotification,
				(map) => InviteLiveCourseNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.JoinLiveCourseNotification,
				(map) => JoinLiveCourseNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.DeviceJoinLiveCourseNotification,
				(map) => DeviceJoinLiveCourseNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.LeaveCoursenNotification,
				(map) => LeaveLiveCourseNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.MuteLiveCourseNotification,
				(map) => MuteLiveCourseNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.NetworkErrCourseNotification,
				(map) => NetworkErrCourseNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.SendLiveInteractiveBoardDataNotification,
				(map) => SendLiveInteractiveBoardDataNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.SwitchLiveCourseVideoNotification,
				(map) => SwitchLiveCourseVideoNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.UpgradeNotification,
				(map) => UpgradeNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.ApplyConsultationNotification,
				(map) => ApplyConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.ApprovalApplyConsultationNotification,
				(map) => ApprovalApplyConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.CloseConsolutionHeartRateToDeviceNotification,
				(map) => CloseConsolutionHeartRateToDeviceNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.ConsultationAnswerTimeout,
				(map) => ConsultationAnswerTimeoutNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.ConsultationRemindNotification,
				(map) => ConsultationRemindNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.InviteeApproveApplyConsultationNotification,
				(map) => InviteeApproveApplyConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.InviteeConsultationNotification,
				(map) => InviteeConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.InviteeRejectApplyConsultationNotification,
				(map) => InviteeRejectApplyConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.RejectApplyConsultationNotification,
				(map) => RejectApplyConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.StartConsolutionHeartRateToDeviceNotification,
				(map) => StartConsolutionHeartRateToDeviceNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.MeetingMemberNotification,
				(map) => MeetingMemberNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.MeetingHangupNotification,
				(map) => MeetingHangupNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.RejectMeetingNotification,
				(map) => RejectMeetingNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.AcceptMeetingNotification,
				(map) => AcceptMeetingNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.MeetingPendingMemberTimeoutNotification,
				(map) => MeetingPendingMemberTimeoutNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.ProbeApplicationSettingResponseNotification,
				(map) => ProbeApplicationSettingResponseNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.CancelLogDownloadNotification,
				(map) => CancelLogDownloadNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.DeviceDownloadPatchProgressToUserNotification,
				(map) => DeviceDownloadPatchProgressToUserNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.DevicePrinterRequestNotification,
				(map) => DevicePrinterRequestNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.DevicePrinterResultNotification,
				(map) => DevicePrinterResultNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.GetRemoteLogToClientNotification,
				(map) => GetRemoteLogToClientNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.GetRemoteLogToDeviceNotification,
				(map) => GetRemoteLogToDeviceNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.PushDevicePatchToDeviceNotification,
				(map) => PushDevicePatchToDeviceNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.RestartDeviceNotification,
				(map) => RestartDeviceNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.AcceptLiveConsultationNotification,
				(map) => AcceptLiveConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.CancelInvitingInLiveConsultationNotification,
				(map) => CancelInvitingInLiveConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.CancelLiveConsultationNotification,
				(map) => CancelLiveConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.CloseLiveConsultationNotification,
				(map) => CloseLiveConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.ChangeConsultationNotification,
				(map) => ChangeConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.ChangeConsultationToDeviceNotification,
				(map) => ChangeConsultationToDeviceNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.CloseConsultationDueToChangeNotification,
				(map) => CloseConsultationDueToChangeNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.EmergencyCallFailedNotification,
				(map) => EmergencyCallFailedNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.EmergencyCallNotification,
				(map) => EmergencyCallNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.HeartRateJoinConsultationNotification,
				(map) => HeartRateJoinConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.HeartRateLeaveConsultationNotification,
				(map) => HeartRateLeaveConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.InviteLiveConsultationNotification,
				(map) => InviteLiveConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.InviteInLiveConsultationNotification,
				(map) => InviteInLiveConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.JoinInLiveConsultationNotification,
				(map) => JoinInLiveConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.RejectInviteLiveConsultationNotification,
				(map) => RejectInviteLiveConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.JoinLiveConsultationNotification,
				(map) => JoinLiveConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.LeaveConsultationNotification,
				(map) => LeaveLiveConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.MuteLiveConsultationNotification,
				(map) => MuteLiveConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.NetworkErrConsultationNotification,
				(map) => NetworkErrConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.RealtimeConsultationMembersNotification,
				(map) => RealtimeConsultationMembersNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.RejectLiveConsultationNotification,
				(map) => RejectLiveConsultationNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.SwitchLiveConsultationVideoNotification,
				(map) => SwitchLiveConsultationVideoNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.UploadConsultationDataNotification,
				(map) => UploadConsultationDataNotification.fromJson(map));

		_builders.add(NotificationTypeEnum.SendInteractiveBoardDataNotification,
				(map) => SendInteractiveBoardDataNotification.fromJson(map));

	}
}

class _ModelBuilderCollection {
	final Map<NotificationTypeEnum, _ModelBuilder> _source = {};

	void add(NotificationTypeEnum type, _ModelBuilder builder) {
		_source[type] = builder;
	}

	_ModelBuilder find(NotificationTypeEnum type) {
		final builder = _source[type];
		return builder!;
	}
}