import '../../utils/kr_log_util.dart';

class KRUserAvailableSubscribeItem {
  final int id;
  final String name;
  final int deviceLimit;
  final int download;
  final int upload;
  final int traffic;
  final String startTime;
  final String expireTime;
  final List<dynamic> list;

  const KRUserAvailableSubscribeItem({
    this.id = 0,
    this.name = '',
    this.deviceLimit = 0,
    this.download = 0,
    this.upload = 0,
    this.traffic = 0,
    this.startTime = '',
    this.expireTime = '',
    this.list = const [],
  });

  factory KRUserAvailableSubscribeItem.fromJson(Map<String, dynamic> json) {
    return KRUserAvailableSubscribeItem(
      id: json['id'] as int? ?? 0,
      name: json['name'] as String? ?? '',
      deviceLimit: json['device_limit'] as int? ?? 0,
      download: json['download'] as int? ?? 0,
      upload: json['upload'] as int? ?? 0,
      traffic: json['traffic'] as int? ?? 0,
      startTime: json['start_time'] as String? ?? '',
      expireTime: json['expire_time'] as String? ?? '',
      list: (json['list'] as List<dynamic>?) ?? const [],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'device_limit': deviceLimit,
      'download': download,
      'upload': upload,
      'traffic': traffic,
      'start_time': startTime,
      'expire_time': expireTime,
      'list': list,
    };
  }
}

class KRUserAvailableSubscribeList {
  final List<KRUserAvailableSubscribeItem> list;

  const KRUserAvailableSubscribeList({
    this.list = const [],
  });

  factory KRUserAvailableSubscribeList.fromJson(Map<String, dynamic> json) {
    KRLogUtil.kr_i('订阅json列表: ${json}', tag: 'KRUserAvailableSubscribeList');
    final List<dynamic> listData = (json['list'] as List<dynamic>?) ?? const [];
    return KRUserAvailableSubscribeList(
      list: listData
          .map((item) => KRUserAvailableSubscribeItem.fromJson(item as Map<String, dynamic>))
          .toList(),
    );
  }
}
