import 'location_model.dart'; enum StopType { pickup, dropoff } enum StopStatus { pending, inProgress, completed, failed } class StopModel { final String id; final String customerId; final String customerName; final String? customerPhone; final LocationModel location; final StopType type; final StopStatus status; final DateTime scheduledTime; final DateTime? completedTime; final String? notes; final List items; final int orderNumber; final String? signature; final String? photo; StopModel({ required this.id, required this.customerId, required this.customerName, this.customerPhone, required this.location, required this.type, required this.status, required this.scheduledTime, this.completedTime, this.notes, required this.items, required this.orderNumber, this.signature, this.photo, }); factory StopModel.fromJson(Map json) { return StopModel( id: json['id'] as String, customerId: json['customerId'] as String, customerName: json['customerName'] as String, customerPhone: json['customerPhone'] as String?, location: LocationModel.fromJson(json['location'] as Map), type: StopType.values.firstWhere( (e) => e.toString() == 'StopType.${json['type']}', ), status: StopStatus.values.firstWhere( (e) => e.toString() == 'StopStatus.${json['status']}', ), scheduledTime: DateTime.parse(json['scheduledTime'] as String), completedTime: json['completedTime'] != null ? DateTime.parse(json['completedTime'] as String) : null, notes: json['notes'] as String?, items: (json['items'] as List).cast(), orderNumber: json['orderNumber'] as int, signature: json['signature'] as String?, photo: json['photo'] as String?, ); } Map toJson() { return { 'id': id, 'customerId': customerId, 'customerName': customerName, 'customerPhone': customerPhone, 'location': location.toJson(), 'type': type.toString().split('.').last, 'status': status.toString().split('.').last, 'scheduledTime': scheduledTime.toIso8601String(), 'completedTime': completedTime?.toIso8601String(), 'notes': notes, 'items': items, 'orderNumber': orderNumber, 'signature': signature, 'photo': photo, }; } StopModel copyWith({ String? id, String? customerId, String? customerName, String? customerPhone, LocationModel? location, StopType? type, StopStatus? status, DateTime? scheduledTime, DateTime? completedTime, String? notes, List? items, int? orderNumber, String? signature, String? photo, }) { return StopModel( id: id ?? this.id, customerId: customerId ?? this.customerId, customerName: customerName ?? this.customerName, customerPhone: customerPhone ?? this.customerPhone, location: location ?? this.location, type: type ?? this.type, status: status ?? this.status, scheduledTime: scheduledTime ?? this.scheduledTime, completedTime: completedTime ?? this.completedTime, notes: notes ?? this.notes, items: items ?? this.items, orderNumber: orderNumber ?? this.orderNumber, signature: signature ?? this.signature, photo: photo ?? this.photo, ); } }