import 'static_talkgroup.dart';
import 'cluster.dart';

class DeviceProfile {
  final List<StaticTalkgroup> blockedGroups;
  final List<StaticTalkgroup> staticSubscriptions;
  final List<StaticTalkgroup> dynamicSubscriptions;
  final List<StaticTalkgroup> timedSubscriptions;
  final List<Cluster> clusters;

  DeviceProfile({
    this.blockedGroups = const [],
    this.staticSubscriptions = const [],
    this.dynamicSubscriptions = const [],
    this.timedSubscriptions = const [],
    this.clusters = const [],
  });

  factory DeviceProfile.fromJson(Map<String, dynamic> json) {
    return DeviceProfile(
      blockedGroups: (json['blockedGroups'] as List<dynamic>?)
              ?.map((e) => StaticTalkgroup.fromJson(e as Map<String, dynamic>))
              .toList() ??
          [],
      staticSubscriptions: (json['staticSubscriptions'] as List<dynamic>?)
              ?.map((e) => StaticTalkgroup.fromJson(e as Map<String, dynamic>))
              .toList() ??
          [],
      dynamicSubscriptions: (json['dynamicSubscriptions'] as List<dynamic>?)
              ?.map((e) => StaticTalkgroup.fromJson(e as Map<String, dynamic>))
              .toList() ??
          [],
      timedSubscriptions: (json['timedSubscriptions'] as List<dynamic>?)
              ?.map((e) => StaticTalkgroup.fromJson(e as Map<String, dynamic>))
              .toList() ??
          [],
      clusters: (json['clusters'] as List<dynamic>?)
              ?.map((e) => Cluster.fromJson(e as Map<String, dynamic>))
              .toList() ??
          [],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'blockedGroups': blockedGroups.map((e) => e.toJson()).toList(),
      'staticSubscriptions': staticSubscriptions.map((e) => e.toJson()).toList(),
      'dynamicSubscriptions':
          dynamicSubscriptions.map((e) => e.toJson()).toList(),
      'timedSubscriptions': timedSubscriptions.map((e) => e.toJson()).toList(),
      'clusters': clusters.map((e) => e.toJson()).toList(),
    };
  }
}
