import 'package:guru_app/ads/core/ads.dart';
import 'package:guru_app/ads/core/strategy/interstitial/max_strategy_interstitial_ads.dart';
import 'package:guru_utils/ads/ads_delegate.dart';
import 'package:guru_utils/ads/data/ads_model.dart';
import 'package:guru_utils/ads/handler/ads_handler.dart';
import 'package:guru_utils/extensions/extensions.dart';

/// Created by Haoyi on 2023/6/27

enum StrategyAdsState { init, idle, loaded, disposed }

enum StrategyAdsPhase { create, loading, loaded, displayed, }

abstract class StrategyAds extends Ads {
  final BehaviorSubject<bool> loadedSubject = BehaviorSubject.seeded(false);

  @override
  set loaded(bool loaded) {
    loadedSubject.addEx(loaded);
    setProperty("isLoaded", loaded ? "true" : "false");
  }

  @override
  bool get loaded => strategy.loaded;

  @override
  Stream<bool> get observableLoaded => strategy.observableLoaded;

  late final AdsStrategy strategy;

  StrategyAds();

  void dispatchEvent(AdsEvent adsEvent,
      {Map<dynamic, dynamic> arguments = const <dynamic, dynamic>{}}) {
    final adsBundle = AdsBundle.create(this, arguments: arguments);
    switch (adsEvent) {
      case AdsEvent.adLoaded:
        onAdLoaded(adsBundle);
        break;
      case AdsEvent.adLoadFailed:
        onAdLoadFailed(adsBundle);
        break;
      case AdsEvent.adDisplayed:
        onAdDisplayed(adsBundle);
        break;
      case AdsEvent.adDisplayFailed:
        onAdDisplayFailed(adsBundle);
        break;
      case AdsEvent.adClick:
        onAdClicked(adsBundle);
        break;
      case AdsEvent.adHidden:
        onAdHidden(adsBundle);
        break;
      case AdsEvent.adRewarded:
        onAdRewarded(adsBundle);
        break;
    }
  }
}
