class AndroidAudioOutputDevice {
  const AndroidAudioOutputDevice({
    required this.id,
    required this.name,
    required this.type,
    required this.isSelected,
    required this.isAvailableForCommunication,
  });

  final String id;
  final String name;
  final String type;
  final bool isSelected;
  final bool isAvailableForCommunication;

  factory AndroidAudioOutputDevice.fromMap(Map<dynamic, dynamic> map) {
    return AndroidAudioOutputDevice(
      id: map['id']?.toString() ?? '',
      name: map['name']?.toString() ?? '',
      type: map['type']?.toString() ?? 'unknown',
      isSelected: map['isSelected'] == true,
      isAvailableForCommunication: map['isAvailableForCommunication'] == true,
    );
  }
}

List<AndroidAudioOutputDevice> parseAndroidAudioOutputDevices(
  List<dynamic> raw,
) {
  return raw
      .whereType<Map<dynamic, dynamic>>()
      .map(AndroidAudioOutputDevice.fromMap)
      .toList();
}

AndroidAudioOutputDevice? selectedAndroidAudioOutputDevice(
  List<AndroidAudioOutputDevice> devices,
) {
  return devices.where((device) => device.isSelected).firstOrNull;
}
