import 'package:equatable/equatable.dart';

enum DeviceTypeEnum {
  all,
  smartBreaker,
  guestControl,
  network,
}

class DeviceInfo {
  final String id;
  final String name;
  final String room;
  final DeviceTypeEnum type;
  final bool online;
  final String status;
  final String lastUpdate;

  const DeviceInfo({
    required this.id,
    required this.name,
    required this.room,
    required this.type,
    required this.online,
    required this.status,
    required this.lastUpdate,
  });

  DeviceInfo copyWith({
    String? id,
    String? name,
    String? room,
    DeviceTypeEnum? type,
    bool? online,
    String? status,
    String? lastUpdate,
  }) {
    return DeviceInfo(
      id: id ?? this.id,
      name: name ?? this.name,
      room: room ?? this.room,
      type: type ?? this.type,
      online: online ?? this.online,
      status: status ?? this.status,
      lastUpdate: lastUpdate ?? this.lastUpdate,
    );
  }
}

class DeviceListState extends Equatable {
  final List<DeviceInfo> devices;
  final DeviceTypeEnum selectedType;

  const DeviceListState({
    this.devices = const [],
    this.selectedType = DeviceTypeEnum.all,
  });

  DeviceListState copyWith({
    List<DeviceInfo>? devices,
    DeviceTypeEnum? selectedType,
  }) {
    return DeviceListState(
      devices: devices ?? this.devices,
      selectedType: selectedType ?? this.selectedType,
    );
  }

  List<DeviceInfo> get filteredDevices {
    if (selectedType == DeviceTypeEnum.all) {
      return devices;
    }
    return devices.where((device) => device.type == selectedType).toList();
  }

  @override
  List<Object?> get props => [devices, selectedType];
}
