import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';

enum RoomStatusTag { hasPerson, powerOn, wifiNormal }

class RoomDevice {
  final String name;
  final IconData icon;
  final bool isOn;
  final String? statusText;

  const RoomDevice({
    required this.name,
    required this.icon,
    this.isOn = false,
    this.statusText,
  });
}

class ControlDevice {
  final int deviceId;
  final String name;
  final IconData icon;
  final bool isOn;
  final String? detailText;
  final String? deviceTypeName;

  const ControlDevice({
    this.deviceId = 0,
    required this.name,
    required this.icon,
    this.isOn = false,
    this.detailText,
    this.deviceTypeName,
  });
}

class ServiceRoomState extends Equatable {
  final bool isLoading;
  final String? error;
  final int roomId;
  final String roomNumber;
  final String roomStatus;
  final List<RoomStatusTag> statusTags;
  final List<RoomDevice> roomDevices;
  final bool mainPowerOn;
  final List<ControlDevice> controlDevices;
  final bool isTogglingPower;

  const ServiceRoomState({
    this.isLoading = false,
    this.error,
    this.roomId = 0,
    this.roomNumber = '',
    this.roomStatus = '',
    this.statusTags = const [],
    this.roomDevices = const [],
    this.mainPowerOn = false,
    this.controlDevices = const [],
    this.isTogglingPower = false,
  });

  ServiceRoomState copyWith({
    bool? isLoading,
    String? error,
    int? roomId,
    String? roomNumber,
    String? roomStatus,
    List<RoomStatusTag>? statusTags,
    List<RoomDevice>? roomDevices,
    bool? mainPowerOn,
    List<ControlDevice>? controlDevices,
    bool? isTogglingPower,
  }) {
    return ServiceRoomState(
      isLoading: isLoading ?? this.isLoading,
      error: error ?? this.error,
      roomId: roomId ?? this.roomId,
      roomNumber: roomNumber ?? this.roomNumber,
      roomStatus: roomStatus ?? this.roomStatus,
      statusTags: statusTags ?? this.statusTags,
      roomDevices: roomDevices ?? this.roomDevices,
      mainPowerOn: mainPowerOn ?? this.mainPowerOn,
      controlDevices: controlDevices ?? this.controlDevices,
      isTogglingPower: isTogglingPower ?? this.isTogglingPower,
    );
  }

  @override
  List<Object?> get props => [
        isLoading,
        error,
        roomId,
        roomNumber,
        roomStatus,
        statusTags,
        roomDevices,
        mainPowerOn,
        controlDevices,
        isTogglingPower,
      ];
}
