class DeviceTopologyBO {
  final DeviceTopologyInfoBO deviceInfo;
  final List<TreeNodeBO> treeNodes;

  const DeviceTopologyBO({
    required this.deviceInfo,
    required this.treeNodes,
  });

  factory DeviceTopologyBO.fromJson(Map<String, dynamic> json) {
    return DeviceTopologyBO(
      deviceInfo: DeviceTopologyInfoBO.fromJson(
        json['deviceInfo'] as Map<String, dynamic>? ?? {},
      ),
      treeNodes: (json['treeNodes'] as List<dynamic>?)
              ?.map((e) => TreeNodeBO.fromJson(e as Map<String, dynamic>))
              .toList() ??
          [],
    );
  }
}

class DeviceTopologyInfoBO {
  final int deviceId;
  final String deviceName;
  final String deviceCode;
  final String deviceLocation;
  final String statusText;

  const DeviceTopologyInfoBO({
    required this.deviceId,
    required this.deviceName,
    required this.deviceCode,
    required this.deviceLocation,
    required this.statusText
  });

  factory DeviceTopologyInfoBO.fromJson(Map<String, dynamic> json) {
    return DeviceTopologyInfoBO(
      deviceId: json['deviceId'] as int? ?? 0,
      deviceName: json['deviceName'] as String? ?? '',
      deviceCode: json['deviceCode'] as String? ?? '',
      deviceLocation: json['deviceLocation'] as String? ?? '',
      statusText: json['statusText'] as String? ?? ''
    );
  }
}

class TreeNodeBO {
  final int deviceId;
  final String deviceName;
  final String deviceType;
  final String icon;
  final String status;
  final String statusText;
  final String deviceCode;
  final int? gatewayId;

  const TreeNodeBO({
    required this.deviceId,
    required this.deviceName,
    required this.deviceType,
    required this.icon,
    required this.status,
    required this.statusText,
    required this.deviceCode,
    this.gatewayId,
  });

  factory TreeNodeBO.fromJson(Map<String, dynamic> json) {
    return TreeNodeBO(
      deviceId: json['deviceId'] as int? ?? 0,
      deviceName: json['deviceName'] as String? ?? '',
      deviceType: json['deviceType'] as String? ?? '',
      icon: json['icon'] as String? ?? '',
      status: json['status'] as String? ?? '',
      statusText: json['statusText'] as String? ?? '',
      deviceCode: json['deviceCode'] as String? ?? '',
      gatewayId: json['gatewayId'] as int?,
    );
  }
}