import 'package:json_annotation/json_annotation.dart';
import 'package:guru_app/ads/core/ads_config.dart';
export 'package:guru_app/ads/core/ads_config.dart';
/// Created by Haoyi on 2022/8/25
///
part 'reserved_remote_config_models.g.dart';

// @JsonSerializable()
// class TaichiConfig {
//   @JsonKey(name: "enable", defaultValue: false)
//   final bool enable;
//
//   @JsonKey(name: "threshold", defaultValue: "")
//   final String threshold;
//
//   @JsonKey(name: "abnormal_threshold", defaultValue: 0.1)
//   final double abnormalThreshold;
//
//   TaichiConfig(
//       {this.enable = false, this.threshold = "", this.abnormalThreshold = 0.1});
//
//   factory TaichiConfig.fromJson(Map<String, dynamic> json) =>
//       _$TaichiConfigFromJson(json);
//
//   @override
//   String toString() {
//     return 'TaichiConfig{enable: $enable, threshold: $threshold}';
//   }
//
//   Map<String, dynamic> toJson() => _$TaichiConfigToJson(this);
// }

@JsonSerializable()
class ImpressionData {
  @JsonKey(name: "ad_platform", defaultValue: "MAX")
  final String platform;

  @JsonKey(name: "id", defaultValue: "")
  final String id;

  @JsonKey(name: "adunit_id", defaultValue: "")
  final String unitId;

  @JsonKey(name: "adunit_name", defaultValue: "")
  final String unitName;

  @JsonKey(name: "adunit_format", defaultValue: "")
  final String unitFormat;

  @JsonKey(name: "adgroup_id", defaultValue: "")
  final String groupId;

  @JsonKey(name: "adgroup_name", defaultValue: "")
  final String groupName;

  @JsonKey(name: "adgroup_type", defaultValue: "")
  final String groupType;

  @JsonKey(name: "currency", defaultValue: "")
  final String currency;

  @JsonKey(name: "country", defaultValue: "")
  final String country;

  @JsonKey(name: "app_version", defaultValue: "")
  final String appVersion;

  @JsonKey(name: "adgroup_priority", defaultValue: 0)
  final int groupPriority;

  @JsonKey(name: "publisher_revenue", defaultValue: -1)
  final double publisherRevenue;

  @JsonKey(name: "network_name", defaultValue: "")
  final String networkName;

  @JsonKey(name: "network_placement_id", defaultValue: "")
  final String networkPlacementId;

  @JsonKey(name: "precision", defaultValue: "")
  final String precision;

  @JsonKey(ignore: true)
  late Map<String, dynamic> payload;

  ImpressionData derive({double? newPublisherRevenue}) {
    final newPayload = Map<String, dynamic>.from(payload);
    newPayload["publisher_revenue"] = newPublisherRevenue ?? publisherRevenue;
    return ImpressionData.fromJson(newPayload);
  }

  @override
  String toString() {
    return 'ImpressionData{platform: $platform, id: $id, unitId: $unitId, unitName: $unitName, unitFormat: $unitFormat, groupId: $groupId, groupName: $groupName, groupType: $groupType, currency: $currency, country: $country, appVersion: $appVersion, groupPriority: $groupPriority, publisherRevenue: $publisherRevenue, networkName: $networkName, networkPlacementId: $networkPlacementId, precision: $precision}';
  }

  ImpressionData(
      {required this.platform,
      required this.id,
      required this.unitId,
      required this.unitName,
      required this.unitFormat,
      required this.groupId,
      required this.groupName,
      required this.groupType,
      required this.currency,
      required this.country,
      required this.appVersion,
      required this.groupPriority,
      required this.publisherRevenue,
      required this.networkName,
      required this.networkPlacementId,
      required this.precision});

  factory ImpressionData.fromJson(Map<String, dynamic> json) =>
      _$ImpressionDataFromJson(json)..payload = json;

  Map<String, dynamic> toJson() => _$ImpressionDataToJson(this);
}

class InvalidABPropertyKeysException implements Exception {
  final Set<String> invalidKeys;
  final dynamic cause;

  InvalidABPropertyKeysException(this.invalidKeys, {this.cause});

  @override
  String toString() {
    return "InvalidABPropertyKeysException: $invalidKeys cause:$cause";
  }
}
