library guru_fb_game;
import 'package:guru_fb_game/model/model.dart';
import 'package:guru_fb_game/utils.dart';

class AppConfig {
  final String appVersion;
  final String appBuildNumber;
  final String guruLogAppId;
  final String bundleId;

  final String? adUnitIdBanner;
  final String? adUnitIdInter;
  final String? adUnitIdRewardVideo;

  const AppConfig({
    required this.appVersion,
    this.appBuildNumber = "1",
    required this.guruLogAppId,
    required this.bundleId,
    this.adUnitIdBanner,
    this.adUnitIdInter,
    this.adUnitIdRewardVideo
  });
}

class GuruFbGame {
  static final GuruFbGame _instance = GuruFbGame._();

  static GuruFbGame get instance => _instance;

  GuruFbGame._();

  FbProfile? fbProfile;

  Map<String, String>? fbtournament;

  Future _initialize(AppConfig config) async {
    // setUrlStrategy(null);
    fbProfile = await FbGameGlobalUtils.getFBProfile();
    final fbPlatform = FbGameGlobalUtils.getPlatform();
    final deviceInfo = GuruLogDeviceData(appId: config.bundleId, version: config.appVersion, fbPlatform: fbPlatform);
    final logInfoData = GuruLogInfoData(deveiceId: '', uid: fbProfile?.userId ?? '');
    final initData = InitGuruLogEventData(appId: config.guruLogAppId, deviceInfo: deviceInfo, info: logInfoData);
    FbGameLogUtils.initGuruLogEvent(initData);
    fbtournament = await FbGameTournamentUtils.getCurrentTournament();
    await initAds(config);
  }

  Future initAds(AppConfig config) async{
    List<String> list = FbGameAdUtils.checkSupportedAds();
    if (list.contains('getInterstitialAdAsync') && config.adUnitIdInter != null) {
      FbGameAdUtils.loadInterstitial(config.adUnitIdInter!);
    }

    if (list.contains('getRewardedVideoAsync') && config.adUnitIdRewardVideo != null) {
      FbGameAdUtils.loadRewarded(config.adUnitIdRewardVideo!);
    }
  }
}