import 'package:equatable/equatable.dart';

class InspectionRoomBO extends Equatable {
  final InspectionRoomRunStatusBO runStatus;
  final List<InspectionRoomGroupsBO> roomGroups;

  const InspectionRoomBO({
    required this.runStatus,
    required this.roomGroups,
  });

  factory InspectionRoomBO.fromJson(Map<String, dynamic> json) {
    final roomGroups = json['roomGroups'] as List<dynamic>? ?? [];
    return InspectionRoomBO(
      runStatus: InspectionRoomRunStatusBO.fromJson(
        json['runStatus'] as Map<String, dynamic>? ?? {},
      ),
      roomGroups: roomGroups
          .map((e) => InspectionRoomGroupsBO.fromJson(e as Map<String, dynamic>))
          .toList(),
    );
  }

  @override
  List<Object?> get props => [runStatus, roomGroups];
}

class InspectionRoomRunStatusBO extends Equatable {
  final int normal;
  final int warning;
  final int offline;
  final int fault;

  const InspectionRoomRunStatusBO({
    required this.normal,
    required this.warning,
    required this.offline,
    required this.fault,
  });

  factory InspectionRoomRunStatusBO.fromJson(Map<String, dynamic> json) {
    return InspectionRoomRunStatusBO(
      normal: int.tryParse(json['normal']?.toString() ?? '') ?? 0,
      warning: int.tryParse(json['warning']?.toString() ?? '') ?? 0,
      offline: int.tryParse(json['offline']?.toString() ?? '') ?? 0,
      fault: int.tryParse(json['fault']?.toString() ?? '') ?? 0,
    );
  }

  @override
  List<Object?> get props => [normal, warning, offline, fault];
}

class InspectionRoomGroupsBO extends Equatable {
  final String areaTypeName;
  final List<InspectionRoomsBO> rooms;

  const InspectionRoomGroupsBO({
    required this.areaTypeName,
    required this.rooms,
  });

  factory InspectionRoomGroupsBO.fromJson(Map<String, dynamic> json) {
    final rooms = json['rooms'] as List<dynamic>? ?? [];
    return InspectionRoomGroupsBO(
      areaTypeName: json['areaTypeName']?.toString() ?? '',
      rooms: rooms
          .map((e) => InspectionRoomsBO.fromJson(e as Map<String, dynamic>))
          .toList(),
    );
  }

  @override
  List<Object?> get props => [areaTypeName, rooms];
}

class InspectionRoomsBO extends Equatable {
  final int roomId;
  final String roomNumber;
  final String areaTypeName;

  const InspectionRoomsBO({
    required this.roomId,
    required this.roomNumber,
    required this.areaTypeName,
  });

  factory InspectionRoomsBO.fromJson(Map<String, dynamic> json) {
    return InspectionRoomsBO(
      roomId: int.tryParse(json['roomId']?.toString() ?? '') ?? 0,
      roomNumber: json['roomNumber']?.toString() ?? '',
      areaTypeName: json['areaTypeName']?.toString() ?? '',
    );
  }

  @override
  List<Object?> get props => [roomId, roomNumber, areaTypeName];
}