Files
tripz-llc/apps/driver_new/lib/features/trip/cubit/duty_state.dart
T
2026-08-05 14:12:41 +03:00

114 lines
3.3 KiB
Dart

import 'package:equatable/equatable.dart';
import '../data/models/geo_point.dart';
import '../data/models/route_info.dart';
import '../data/models/trip.dart';
/// حالة السائق. الفرق الجوهري عن الراكب: السائق **يستقبل** عملاً بدل أن
/// يطلبه، فالمحور هنا الاتصال والعرض لا التخطيط.
enum DutyPhase {
/// غير متصل — لا يصله شيء.
offline,
/// متصل بانتظار عرض.
waiting,
/// عرض معروض بمؤقّت.
offered,
/// رحلة مقبولة جارية.
active,
}
enum DutyError { none, goOnlineFailed, acceptFailed, offerTaken, statusFailed }
class DutyState extends Equatable {
const DutyState({
this.phase = DutyPhase.offline,
this.myLocation,
this.offer,
this.trip,
this.busy = false,
this.error = DutyError.none,
this.creditBalance,
this.creditBlocked = false,
this.navRoute,
});
final DutyPhase phase;
final GeoPoint? myLocation;
/// العرض المعروض حالياً — يختفي إن سبق إليه سائق آخر.
final Trip? offer;
final Trip? trip;
final bool busy;
final DutyError error;
/// الرصيد التشغيلي: العمولة تُخصم منه عند الإنهاء (docs/38 §5).
final String? creditBalance;
/// محجوب لنفاد الرصيد — لا يصله عمل، ولا بد أن يعرف السبب صراحةً.
final bool creditBlocked;
/// المسار الذي يقوده السائق الآن: إليه إن كان مقترباً، وإلى وجهة الراكب
/// إن كانت الرحلة جارية. **بلا هذا السائق أعمى** — كان يرى موقعه وحده.
final RouteInfo? navRoute;
/// الهدف الحالي للقيادة — نقطة الراكب أثناء الاقتراب، ثم الوجهة.
///
/// آلة الحالات هي من تقرّره لا الشاشة (docs/38 §4).
GeoPoint? get navTarget => switch (trip?.status) {
TripStatus.assigned ||
TripStatus.driverArriving ||
TripStatus.driverArrived =>
trip?.origin,
TripStatus.inProgress => trip?.destination,
_ => null,
};
bool get isOnline => phase != DutyPhase.offline;
DutyState copyWith({
DutyPhase? phase,
GeoPoint? myLocation,
Trip? offer,
Trip? trip,
bool? busy,
DutyError? error,
String? creditBalance,
bool? creditBlocked,
RouteInfo? navRoute,
bool clearOffer = false,
bool clearTrip = false,
bool clearNavRoute = false,
}) {
return DutyState(
phase: phase ?? this.phase,
myLocation: myLocation ?? this.myLocation,
offer: clearOffer ? null : (offer ?? this.offer),
trip: clearTrip ? null : (trip ?? this.trip),
busy: busy ?? this.busy,
error: error ?? this.error,
creditBalance: creditBalance ?? this.creditBalance,
creditBlocked: creditBlocked ?? this.creditBlocked,
navRoute: clearNavRoute || clearTrip
? null
: (navRoute ?? this.navRoute),
);
}
@override
List<Object?> get props => [
phase,
myLocation,
offer,
trip,
busy,
error,
creditBalance,
creditBlocked,
navRoute,
];
}