part of 'scan_history_bloc.dart';

abstract class ScanHistoryState extends Equatable {
  final DateTime? selectedDate;
  final String selectedStatus;

  const ScanHistoryState({
    this.selectedDate,
    required this.selectedStatus,
  });

  @override
  List<Object?> get props => [selectedDate, selectedStatus];
}

class ScanHistoryInitial extends ScanHistoryState {
  ScanHistoryInitial({DateTime? date, String? status})
      : super(
          selectedDate: date, // Null means 'All'
          selectedStatus: status ?? 'all',
        );
}

class ScanHistoryLoading extends ScanHistoryState {
  const ScanHistoryLoading({super.selectedDate, required super.selectedStatus});
}

class ScanHistoryLoaded extends ScanHistoryState {
  final List<ScanHistory> allItems;
  final List<ScanHistory> filteredItems;
  final String searchQuery;
  final bool isRefreshing;

  const ScanHistoryLoaded({
    super.selectedDate,
    required super.selectedStatus,
    required this.allItems,
    required this.filteredItems,
    this.searchQuery = '',
    this.isRefreshing = false,
  });

  ScanHistoryLoaded copyWith({
    List<ScanHistory>? allItems,
    List<ScanHistory>? filteredItems,
    String? searchQuery,
    bool? isRefreshing,
    DateTime? selectedDate,
    bool clearDate = false,
    String? selectedStatus,
  }) {
    return ScanHistoryLoaded(
      allItems: allItems ?? this.allItems,
      filteredItems: filteredItems ?? this.filteredItems,
      searchQuery: searchQuery ?? this.searchQuery,
      isRefreshing: isRefreshing ?? this.isRefreshing,
      selectedDate: clearDate ? null : (selectedDate ?? this.selectedDate),
      selectedStatus: selectedStatus ?? this.selectedStatus,
    );
  }

  @override
  List<Object?> get props => [allItems, filteredItems, searchQuery, isRefreshing, selectedDate, selectedStatus];
}

class ScanHistoryDetailState extends ScanHistoryState {
  final ScanHistory selectedItem;
  final List<ScanHistory> allItems;
  final List<ScanHistory> filteredItems;
  final String searchQuery;

  const ScanHistoryDetailState({
    super.selectedDate,
    required super.selectedStatus,
    required this.selectedItem,
    required this.allItems,
    required this.filteredItems,
    required this.searchQuery,
  });

  @override
  List<Object?> get props => [selectedItem, allItems, filteredItems, searchQuery, selectedDate, selectedStatus];
}

class ScanHistoryError extends ScanHistoryState {
  final String errorMessage;

  const ScanHistoryError({
    super.selectedDate,
    required super.selectedStatus,
    required this.errorMessage,
  });

  @override
  List<Object?> get props => [errorMessage, selectedDate, selectedStatus];
}