244 lines
7.8 KiB
Dart
244 lines
7.8 KiB
Dart
import 'package:equatable/equatable.dart';
|
|
import 'package:flux/features/tickets/models/ticket_model.dart';
|
|
import 'package:flux/features/tracking/models/tracking_model.dart';
|
|
|
|
class PublicTicketTimelineItem extends Equatable {
|
|
final String id;
|
|
final DateTime createdAt;
|
|
final TrackingType eventType;
|
|
final String message;
|
|
|
|
const PublicTicketTimelineItem({
|
|
required this.id,
|
|
required this.createdAt,
|
|
required this.eventType,
|
|
required this.message,
|
|
});
|
|
|
|
static final empty = PublicTicketTimelineItem(
|
|
id: '',
|
|
createdAt: DateTime.fromMillisecondsSinceEpoch(0),
|
|
eventType: TrackingType.manualNote,
|
|
message: '',
|
|
);
|
|
|
|
PublicTicketTimelineItem copyWith({
|
|
String? id,
|
|
DateTime? createdAt,
|
|
TrackingType? eventType,
|
|
String? message,
|
|
}) {
|
|
return PublicTicketTimelineItem(
|
|
id: id ?? this.id,
|
|
createdAt: createdAt ?? this.createdAt,
|
|
eventType: eventType ?? this.eventType,
|
|
message: message ?? this.message,
|
|
);
|
|
}
|
|
|
|
factory PublicTicketTimelineItem.fromMap(Map<String, dynamic> map) {
|
|
return PublicTicketTimelineItem(
|
|
id: map['id']?.toString() ?? '',
|
|
createdAt: map['created_at'] != null
|
|
? DateTime.parse(map['created_at'].toString()).toLocal()
|
|
: DateTime.now(),
|
|
eventType: TrackingType.fromString(map['event_type']?.toString() ?? ''),
|
|
message: map['message']?.toString() ?? '',
|
|
);
|
|
}
|
|
|
|
@override
|
|
List<Object?> get props => [id, createdAt, eventType, message];
|
|
}
|
|
|
|
class PublicTicketModel extends Equatable {
|
|
final String id;
|
|
final String? referenceId;
|
|
final DateTime? createdAt;
|
|
final DateTime? closedAt;
|
|
final DateTime? returnedAt;
|
|
final DateTime? estimatedDeliveryAt;
|
|
final TicketType ticketType;
|
|
final TicketStatus ticketStatus;
|
|
final TicketResult? ticketResult;
|
|
final WarrantyType? warrantyType;
|
|
final String request;
|
|
final String? includedAccessories;
|
|
final bool hasCourtesyDevice;
|
|
final double customerPrice;
|
|
final String? publicNotes;
|
|
final String? resolutionNotes;
|
|
final String? targetModelName;
|
|
final String? customerName;
|
|
final String? companyName;
|
|
final String? companyPhone;
|
|
final String? companyEmail;
|
|
final String? companyAddress;
|
|
final String? companyCity;
|
|
final String? storeName;
|
|
final List<PublicTicketTimelineItem> timeline;
|
|
|
|
const PublicTicketModel({
|
|
required this.id,
|
|
this.referenceId,
|
|
this.createdAt,
|
|
this.closedAt,
|
|
this.returnedAt,
|
|
this.estimatedDeliveryAt,
|
|
this.ticketType = TicketType.repair,
|
|
this.ticketStatus = TicketStatus.open,
|
|
this.ticketResult,
|
|
this.warrantyType,
|
|
this.request = '',
|
|
this.includedAccessories,
|
|
this.hasCourtesyDevice = false,
|
|
this.customerPrice = 0.0,
|
|
this.publicNotes,
|
|
this.resolutionNotes,
|
|
this.targetModelName,
|
|
this.customerName,
|
|
this.companyName,
|
|
this.companyPhone,
|
|
this.companyEmail,
|
|
this.companyAddress,
|
|
this.companyCity,
|
|
this.storeName,
|
|
this.timeline = const [],
|
|
});
|
|
|
|
static const empty = PublicTicketModel(id: '');
|
|
|
|
PublicTicketModel copyWith({
|
|
String? id,
|
|
String? referenceId,
|
|
DateTime? createdAt,
|
|
DateTime? closedAt,
|
|
DateTime? returnedAt,
|
|
DateTime? estimatedDeliveryAt,
|
|
TicketType? ticketType,
|
|
TicketStatus? ticketStatus,
|
|
TicketResult? ticketResult,
|
|
WarrantyType? warrantyType,
|
|
String? request,
|
|
String? includedAccessories,
|
|
bool? hasCourtesyDevice,
|
|
double? customerPrice,
|
|
String? publicNotes,
|
|
String? resolutionNotes,
|
|
String? targetModelName,
|
|
String? customerName,
|
|
String? companyName,
|
|
String? companyPhone,
|
|
String? companyEmail,
|
|
String? companyAddress,
|
|
String? companyCity,
|
|
String? storeName,
|
|
List<PublicTicketTimelineItem>? timeline,
|
|
}) {
|
|
return PublicTicketModel(
|
|
id: id ?? this.id,
|
|
referenceId: referenceId ?? this.referenceId,
|
|
createdAt: createdAt ?? this.createdAt,
|
|
closedAt: closedAt ?? this.closedAt,
|
|
returnedAt: returnedAt ?? this.returnedAt,
|
|
estimatedDeliveryAt: estimatedDeliveryAt ?? this.estimatedDeliveryAt,
|
|
ticketType: ticketType ?? this.ticketType,
|
|
ticketStatus: ticketStatus ?? this.ticketStatus,
|
|
ticketResult: ticketResult ?? this.ticketResult,
|
|
warrantyType: warrantyType ?? this.warrantyType,
|
|
request: request ?? this.request,
|
|
includedAccessories: includedAccessories ?? this.includedAccessories,
|
|
hasCourtesyDevice: hasCourtesyDevice ?? this.hasCourtesyDevice,
|
|
customerPrice: customerPrice ?? this.customerPrice,
|
|
publicNotes: publicNotes ?? this.publicNotes,
|
|
resolutionNotes: resolutionNotes ?? this.resolutionNotes,
|
|
targetModelName: targetModelName ?? this.targetModelName,
|
|
customerName: customerName ?? this.customerName,
|
|
companyName: companyName ?? this.companyName,
|
|
companyPhone: companyPhone ?? this.companyPhone,
|
|
companyEmail: companyEmail ?? this.companyEmail,
|
|
companyAddress: companyAddress ?? this.companyAddress,
|
|
companyCity: companyCity ?? this.companyCity,
|
|
storeName: storeName ?? this.storeName,
|
|
timeline: timeline ?? this.timeline,
|
|
);
|
|
}
|
|
|
|
factory PublicTicketModel.fromMap(Map<String, dynamic> map) {
|
|
final rawTimeline = map['timeline'] as List? ?? const [];
|
|
return PublicTicketModel(
|
|
id: map['id']?.toString() ?? '',
|
|
referenceId: map['reference_id'] as String?,
|
|
createdAt: map['created_at'] != null
|
|
? DateTime.parse(map['created_at'].toString()).toLocal()
|
|
: null,
|
|
closedAt: map['closed_at'] != null
|
|
? DateTime.parse(map['closed_at'].toString()).toLocal()
|
|
: null,
|
|
returnedAt: map['returned_at'] != null
|
|
? DateTime.parse(map['returned_at'].toString()).toLocal()
|
|
: null,
|
|
estimatedDeliveryAt: map['estimated_delivery_at'] != null
|
|
? DateTime.parse(map['estimated_delivery_at'].toString()).toLocal()
|
|
: null,
|
|
ticketType: TicketType.fromString(map['ticket_type']?.toString() ?? ''),
|
|
ticketStatus: TicketStatus.fromString(map['ticket_status']?.toString()),
|
|
ticketResult: TicketResult.fromString(map['ticket_result']?.toString()),
|
|
warrantyType: map['warranty_type'] != null
|
|
? WarrantyType.fromString(map['warranty_type'].toString())
|
|
: null,
|
|
request: map['request']?.toString() ?? '',
|
|
includedAccessories: map['included_accessories'] as String?,
|
|
hasCourtesyDevice: map['has_courtesy_device'] as bool? ?? false,
|
|
customerPrice: (map['customer_price'] as num?)?.toDouble() ?? 0.0,
|
|
publicNotes: map['public_notes'] as String?,
|
|
resolutionNotes: map['resolution_notes'] as String?,
|
|
targetModelName: map['target_model_name'] as String?,
|
|
customerName: map['customer_name'] as String?,
|
|
companyName: map['company_name'] as String?,
|
|
companyPhone: map['company_phone'] as String?,
|
|
companyEmail: map['company_email'] as String?,
|
|
companyAddress: map['company_address'] as String?,
|
|
companyCity: map['company_city'] as String?,
|
|
storeName: map['store_name'] as String?,
|
|
timeline: rawTimeline
|
|
.whereType<Map>()
|
|
.map(
|
|
(e) => PublicTicketTimelineItem.fromMap(
|
|
Map<String, dynamic>.from(e),
|
|
),
|
|
)
|
|
.toList(),
|
|
);
|
|
}
|
|
|
|
@override
|
|
List<Object?> get props => [
|
|
id,
|
|
referenceId,
|
|
createdAt,
|
|
closedAt,
|
|
returnedAt,
|
|
estimatedDeliveryAt,
|
|
ticketType,
|
|
ticketStatus,
|
|
ticketResult,
|
|
warrantyType,
|
|
request,
|
|
includedAccessories,
|
|
hasCourtesyDevice,
|
|
customerPrice,
|
|
publicNotes,
|
|
resolutionNotes,
|
|
targetModelName,
|
|
customerName,
|
|
companyName,
|
|
companyPhone,
|
|
companyEmail,
|
|
companyAddress,
|
|
companyCity,
|
|
storeName,
|
|
timeline,
|
|
];
|
|
}
|