import 'package:equatable/equatable.dart';
import 'package:krow_domain/krow_domain.dart';

enum ClockInStatus { initial, loading, success, failure, actionInProgress }

/// View model representing the user's current attendance state.
class AttendanceStatus extends Equatable {
  final bool isCheckedIn;
  final DateTime? checkInTime;
  final DateTime? checkOutTime;
  final String? activeShiftId;

  const AttendanceStatus({
    this.isCheckedIn = false,
    this.checkInTime,
    this.checkOutTime,
    this.activeShiftId,
  });

  @override
  List<Object?> get props => [isCheckedIn, checkInTime, checkOutTime, activeShiftId];
}

class ClockInState extends Equatable {
  final ClockInStatus status;
  final Shift? todayShift;
  final AttendanceStatus attendance;
  final List<Map<String, dynamic>> activityLog;
  final DateTime selectedDate;
  final String checkInMode;
  final String? errorMessage;

  const ClockInState({
    this.status = ClockInStatus.initial,
    this.todayShift,
    this.attendance = const AttendanceStatus(),
    this.activityLog = const [],
    required this.selectedDate,
    this.checkInMode = 'swipe',
    this.errorMessage,
  });

  ClockInState copyWith({
    ClockInStatus? status,
    Shift? todayShift,
    AttendanceStatus? attendance,
    List<Map<String, dynamic>>? activityLog,
    DateTime? selectedDate,
    String? checkInMode,
    String? errorMessage,
  }) {
    return ClockInState(
      status: status ?? this.status,
      todayShift: todayShift ?? this.todayShift,
      attendance: attendance ?? this.attendance,
      activityLog: activityLog ?? this.activityLog,
      selectedDate: selectedDate ?? this.selectedDate,
      checkInMode: checkInMode ?? this.checkInMode,
      errorMessage: errorMessage,
    );
  }

  @override
  List<Object?> get props => [
        status,
        todayShift,
        attendance,
        activityLog,
        selectedDate,
        checkInMode,
        errorMessage,
      ];
}
