import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:flux/features/tickets/models/ticket_model.dart';

class TicketListState extends Equatable {
  final List<TicketModel> tickets;
  final bool isLoading;
  final bool hasReachedMax;
  final String errorMessage;
  final Set<TicketModel> selectedTickets;

  // Filtri attivi
  final String? searchTerm;
  final DateTimeRange? dateRange;
  final TicketStatus? statusFilter;
  final TicketType? ticketTypeFilter;
  final String? staffIdFilter;

  const TicketListState({
    this.tickets = const [],
    this.isLoading = false,
    this.hasReachedMax = false,
    this.errorMessage = '',
    this.selectedTickets = const {},
    this.searchTerm,
    this.dateRange,
    this.statusFilter,
    this.ticketTypeFilter,
    this.staffIdFilter,
  });

  TicketListState copyWith({
    List<TicketModel>? tickets,
    bool? isLoading,
    bool? hasReachedMax,
    String? errorMessage,
    Set<TicketModel>? selectedTickets,
    String? searchTerm,
    DateTimeRange? dateRange,
    TicketStatus? statusFilter,
    TicketType? ticketTypeFilter,
    String? staffIdFilter,
    bool clearSearch = false,
    bool clearDate = false,
    bool clearStatus = false,
  }) {
    return TicketListState(
      tickets: tickets ?? this.tickets,
      isLoading: isLoading ?? this.isLoading,
      hasReachedMax: hasReachedMax ?? this.hasReachedMax,
      errorMessage: errorMessage ?? this.errorMessage,
      searchTerm: clearSearch ? null : (searchTerm ?? this.searchTerm),
      dateRange: clearDate ? null : (dateRange ?? this.dateRange),
      statusFilter: clearStatus ? null : (statusFilter ?? this.statusFilter),
      ticketTypeFilter: ticketTypeFilter ?? this.ticketTypeFilter,
      staffIdFilter: staffIdFilter ?? this.staffIdFilter,
      selectedTickets: selectedTickets ?? this.selectedTickets,
    );
  }

  @override
  List<Object?> get props => [
    tickets,
    isLoading,
    hasReachedMax,
    errorMessage,
    selectedTickets,
    searchTerm,
    dateRange,
    statusFilter,
    ticketTypeFilter,
    staffIdFilter,
  ];
}
