92 lines
2.4 KiB
Dart
92 lines
2.4 KiB
Dart
import 'package:equatable/equatable.dart';
|
|
import 'package:flux/core/services/email/email_response_model.dart';
|
|
import 'package:flux/core/services/whatsapp/whatsapp_response_model.dart';
|
|
|
|
enum TicketNotificationChannel {
|
|
whatsapp('WhatsApp'),
|
|
email('Email');
|
|
|
|
final String label;
|
|
const TicketNotificationChannel(this.label);
|
|
}
|
|
|
|
class TicketNotificationResult extends Equatable {
|
|
final TicketNotificationChannel channel;
|
|
final bool success;
|
|
final bool? whatsappExists;
|
|
final String? destination;
|
|
final String? error;
|
|
final String contextLabel;
|
|
|
|
const TicketNotificationResult({
|
|
required this.channel,
|
|
required this.success,
|
|
this.whatsappExists,
|
|
this.destination,
|
|
this.error,
|
|
this.contextLabel = 'Avviso',
|
|
});
|
|
|
|
static const empty = TicketNotificationResult(
|
|
channel: TicketNotificationChannel.whatsapp,
|
|
success: false,
|
|
);
|
|
|
|
factory TicketNotificationResult.fromWhatsApp(
|
|
WhatsAppResponse response, {
|
|
String? fallbackDestination,
|
|
String contextLabel = 'Avviso',
|
|
}) {
|
|
return TicketNotificationResult(
|
|
channel: TicketNotificationChannel.whatsapp,
|
|
success: response.success,
|
|
whatsappExists: response.exists,
|
|
destination: response.phone ?? fallbackDestination,
|
|
error: response.error,
|
|
contextLabel: contextLabel,
|
|
);
|
|
}
|
|
|
|
factory TicketNotificationResult.fromEmail(
|
|
EmailResponse response, {
|
|
String? fallbackDestination,
|
|
String contextLabel = 'Avviso',
|
|
}) {
|
|
return TicketNotificationResult(
|
|
channel: TicketNotificationChannel.email,
|
|
success: response.success,
|
|
destination: response.to ?? fallbackDestination,
|
|
error: response.error,
|
|
contextLabel: contextLabel,
|
|
);
|
|
}
|
|
|
|
TicketNotificationResult copyWith({
|
|
TicketNotificationChannel? channel,
|
|
bool? success,
|
|
bool? whatsappExists,
|
|
String? destination,
|
|
String? error,
|
|
String? contextLabel,
|
|
}) {
|
|
return TicketNotificationResult(
|
|
channel: channel ?? this.channel,
|
|
success: success ?? this.success,
|
|
whatsappExists: whatsappExists ?? this.whatsappExists,
|
|
destination: destination ?? this.destination,
|
|
error: error ?? this.error,
|
|
contextLabel: contextLabel ?? this.contextLabel,
|
|
);
|
|
}
|
|
|
|
@override
|
|
List<Object?> get props => [
|
|
channel,
|
|
success,
|
|
whatsappExists,
|
|
destination,
|
|
error,
|
|
contextLabel,
|
|
];
|
|
}
|