Files
krow-worker-app/lib/models/worker.dart
2026-09-17 22:26:11 +05:30

58 lines
1.4 KiB
Dart

class Worker {
const Worker({
required this.name,
required this.role,
required this.city,
required this.phone,
this.shiftsWorked = 0,
this.rating = 5.0,
this.onTimePercent = 100,
this.noShows = 0,
this.cancellations = 0,
});
final String name;
final String role;
final String city;
final String phone;
final int shiftsWorked;
final double rating;
final int onTimePercent;
final int noShows;
final int cancellations;
/// Stay above 45% to keep picking up shifts. On-time arrivals move it most.
int get trustIndex {
final base = 40 + onTimePercent ~/ 2 - noShows * 15 - cancellations * 5;
return base.clamp(0, 100);
}
String get initials => name
.split(' ')
.where((p) => p.isNotEmpty)
.map((p) => p[0].toUpperCase())
.take(2)
.join();
Worker copyWith({
String? name,
String? role,
String? city,
String? phone,
int? shiftsWorked,
int? onTimePercent,
int? noShows,
int? cancellations,
}) => Worker(
name: name ?? this.name,
role: role ?? this.role,
city: city ?? this.city,
phone: phone ?? this.phone,
shiftsWorked: shiftsWorked ?? this.shiftsWorked,
rating: rating,
onTimePercent: onTimePercent ?? this.onTimePercent,
noShows: noShows ?? this.noShows,
cancellations: cancellations ?? this.cancellations,
);
}