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

enum BreakStatus { neutral, positive, negative }

class CompleteDialogState extends Equatable {
  final BreakStatus status;
  final String? selectedReason;
  final String startTime;
  final String endTime;
  final String additionalReason;
  final DateTime? minLimit;
  final Duration breakDuration;

  const CompleteDialogState({
    this.status = BreakStatus.neutral,
    this.selectedReason,
    this.startTime = '00:00',
    this.endTime = '00:00',
    this.additionalReason = '',
    this.minLimit,
    this.breakDuration = const Duration(minutes: 0),
  });

  String? get breakTimeInputError {
    if (startTime == endTime) {
      return 'Break start time and end time cannot be the same';
    }
    if (DateFormat('H:mm')
        .parse(startTime)
        .isAfter(DateFormat('H:mm').parse(endTime))) {
      return 'Break start time cannot be after break end time';
    }
    if (DateFormat('H:mm').parse(endTime).isAfter(DateTime.now())) {
      return 'Break end time cannot be in the future';
    }

    if (minLimit != null) {
      final start = DateFormat('H:mm').parse(startTime);
      final min =
          DateFormat('H:mm').parse(DateFormat('H:mm').format(minLimit!));
      if (start.isBefore(min)) {
        return 'Break start time cannot be before the shift start time';
      }
    }

    return null;
  }

  CompleteDialogState copyWith({
    BreakStatus? status,
    String? selectedReason,
    String? startTime,
    String? endTime,
    String? additionalReason,
    DateTime? minLimit,
    Duration? breakDuration,
  }) {
    return CompleteDialogState(
      status: status ?? this.status,
      selectedReason: selectedReason ?? this.selectedReason,
      startTime: startTime ?? this.startTime,
      endTime: endTime ?? this.endTime,
      additionalReason: additionalReason ?? this.additionalReason,
      minLimit: minLimit ?? this.minLimit,
      breakDuration: breakDuration ?? this.breakDuration,
    );
  }

  @override
  List<Object?> get props =>
      [status, selectedReason, startTime, endTime, additionalReason];
}
