import 'package:equatable/equatable.dart';

class ServiceIndexState extends Equatable {
  /// copyWith sentinel: 区分「未传参」和「显式传 null」
  static const _nothing = Object();

  final int pendingCount;
  final int occupiedRooms;
  final int vacantRooms;
  final List<Map<int,String>>? floors;
  final List<String> areas;
  final String? selectedFloor;
  final String? selectedType;
  final String? selectedRoom;
  final int? selectedRoomId;
  final String searchText;
  final List<Map<String, dynamic>> rooms;
  final bool isLoading;
  final String? error;
  final bool isPoweringOn;
  final bool isPoweringOff;

  const ServiceIndexState({
    this.pendingCount = 0,
    this.occupiedRooms = 0,
    this.vacantRooms = 0,
    this.floors = const [],
    this.areas = const [],
    this.selectedFloor,
    this.selectedType,
    this.selectedRoom,
    this.selectedRoomId,
    this.searchText = '',
    this.rooms = const [],
    this.isLoading = false,
    this.error,
    this.isPoweringOn = false,
    this.isPoweringOff = false,
  });

  ServiceIndexState copyWith({
    int? pendingCount,
    int? occupiedRooms,
    int? vacantRooms,
    List<Map<int,String>>? floors,
    List<String>? areas,
    Object? selectedFloor = _nothing,
    Object? selectedType = _nothing,
    Object? selectedRoom = _nothing,
    Object? selectedRoomId = _nothing,
    String? searchText,
    List<Map<String, dynamic>>? rooms,
    bool? isLoading,
    Object? error = _nothing,
    bool? isPoweringOn,
    bool? isPoweringOff,
  }) {
    return ServiceIndexState(
      pendingCount: pendingCount ?? this.pendingCount,
      occupiedRooms: occupiedRooms ?? this.occupiedRooms,
      vacantRooms: vacantRooms ?? this.vacantRooms,
      floors: floors ?? this.floors,
      areas: areas ?? this.areas,
      selectedFloor: identical(selectedFloor, _nothing) ? this.selectedFloor : selectedFloor as String?,
      selectedType: identical(selectedType, _nothing) ? this.selectedType : selectedType as String?,
      selectedRoom: identical(selectedRoom, _nothing) ? this.selectedRoom : selectedRoom as String?,
      selectedRoomId: identical(selectedRoomId, _nothing) ? this.selectedRoomId : selectedRoomId as int?,
      searchText: searchText ?? this.searchText,
      rooms: rooms ?? this.rooms,
      isLoading: isLoading ?? this.isLoading,
      error: identical(error, _nothing) ? this.error : error as String?,
      isPoweringOn: isPoweringOn ?? this.isPoweringOn,
      isPoweringOff: isPoweringOff ?? this.isPoweringOff,
    );
  }

  @override
  List<Object?> get props => [
        pendingCount,
        occupiedRooms,
        vacantRooms,
        floors,
        areas,
        selectedFloor,
        selectedType,
        selectedRoom,
        selectedRoomId,
        searchText,
        rooms,
        isLoading,
        error,
        isPoweringOn,
        isPoweringOff,
      ];
}