import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/foundation.dart';

class FirebaseAnalyticsManager {
  /// 仅在非调试版本中启用它
  static Future<void> setCrashlyticsCollectionEnabled() async {
    await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(!kDebugMode);
  }

  /// 埋点
  /// name：事件名
  /// parameters：业务参数
  static void logEvent(String eventName, {Map<String, Object>? parameters}) {
    FirebaseAnalytics.instance.logEvent(
      name: eventName,
      parameters: parameters,
    );
  }

  /// 广告日志记录
  static logAdImpression(String adId, String adName, int shouldCount, int successCount, int failCount) {
    FirebaseAnalytics.instance.logEvent(
      name: 'ad_impression',
      parameters: {
        'adId': adId,
        'adName': adName,
        'shouldCount': shouldCount,
        'successCount': successCount,
        'failCount': failCount,
      },
    );
  }
}
