/// A data-transfer object representing a driver’s last known coordinates. /// /// Matches the Java class: class DriverLocationDto { /// The driver’s primary-key ID. final int driverId; /// Current latitude in WGS-84 (positive = north). final double latitude; /// Current longitude in WGS-84 (positive = east). final double longitude; final double? bearing; final double? distanceKm; final int? etaSeconds; const DriverLocationDto({ required this.driverId, required this.latitude, required this.longitude, this.bearing, this.distanceKm, this.etaSeconds, }); /* ───────────────────────── JSON helpers ────────────────────────── */ /// Builds the DTO from a decoded JSON map (`Map`). factory DriverLocationDto.fromJson(Map json) => DriverLocationDto( driverId: (json['driverId'] ?? json['driverID'] ?? json['id']) as int, latitude: (json['latitude'] as num).toDouble(), longitude: (json['longitude'] as num).toDouble(), distanceKm: json['distanceKm'] ??0, etaSeconds: json['etaSeconds'] ??0, bearing: (json['bearing'] as num?)?.toDouble(), ); /// Converts the DTO back into JSON (for WebSocket, REST, etc.). Map toJson() => { 'driverId': driverId, 'latitude': latitude, 'longitude': longitude, 'bearing': bearing, 'distanceKm': distanceKm, 'etaSeconds': etaSeconds, }; /* ───────────────────────── utilities ───────────────────────────── */ @override String toString() => 'DriverLocationDto(driverId: $driverId, lat: $latitude, lng: $longitude,bearing : $bearing,distanceKm : $distanceKm,etaSeconds : $etaSeconds)'; /// Handy when you need to create a slightly modified copy. DriverLocationDto copyWith({ int? driverId, double? latitude, double? longitude, double? bearing, double? distanceKm, int? etaSeconds, }) => DriverLocationDto( driverId: driverId ?? this.driverId, latitude: latitude ?? this.latitude, longitude: longitude ?? this.longitude, bearing: bearing ?? this.bearing, distanceKm: distanceKm ?? this.distanceKm, etaSeconds: etaSeconds ?? this.etaSeconds, ); /// Equality & hashCode so you can use the object in collections. @override bool operator ==(Object other) => identical(this, other) || other is DriverLocationDto && runtimeType == other.runtimeType && driverId == other.driverId && latitude == other.latitude && longitude == other.longitude && etaSeconds == other.etaSeconds && distanceKm == other.distanceKm && bearing == other.bearing; @override int get hashCode => Object.hash(driverId, latitude, longitude, bearing, etaSeconds, distanceKm); }