import '../utils/app_time.dart'; class AttendanceLog { AttendanceLog({ required this.id, required this.userId, required this.dutyScheduleId, required this.shiftType, required this.checkInAt, required this.checkInLat, required this.checkInLng, this.checkOutAt, this.checkOutLat, this.checkOutLng, this.justification, this.checkOutJustification, this.verificationStatus = 'pending', this.checkInVerificationPhotoUrl, this.checkOutVerificationPhotoUrl, }); final String id; final String userId; final String dutyScheduleId; final String shiftType; final DateTime checkInAt; final double checkInLat; final double checkInLng; final DateTime? checkOutAt; final double? checkOutLat; final double? checkOutLng; final String? justification; final String? checkOutJustification; final String verificationStatus; // pending, verified, unverified, skipped final String? checkInVerificationPhotoUrl; final String? checkOutVerificationPhotoUrl; bool get isCheckedOut => checkOutAt != null; bool get isVerified => verificationStatus == 'verified'; bool get isUnverified => verificationStatus == 'unverified' || verificationStatus == 'skipped'; factory AttendanceLog.fromMap(Map map) { // Support both old single-column and new dual-column schemas. final legacyUrl = map['verification_photo_url'] as String?; return AttendanceLog( id: map['id'] as String, userId: map['user_id'] as String, dutyScheduleId: map['duty_schedule_id'] as String, shiftType: map['shift_type'] as String? ?? 'normal', checkInAt: AppTime.parse(map['check_in_at'] as String), checkInLat: (map['check_in_lat'] as num).toDouble(), checkInLng: (map['check_in_lng'] as num).toDouble(), checkOutAt: map['check_out_at'] == null ? null : AppTime.parse(map['check_out_at'] as String), checkOutLat: (map['check_out_lat'] as num?)?.toDouble(), checkOutLng: (map['check_out_lng'] as num?)?.toDouble(), justification: map['justification'] as String?, checkOutJustification: map['check_out_justification'] as String?, verificationStatus: map['verification_status'] as String? ?? 'pending', checkInVerificationPhotoUrl: map['check_in_verification_photo_url'] as String? ?? legacyUrl, checkOutVerificationPhotoUrl: map['check_out_verification_photo_url'] as String?, ); } }