import 'package:yumi/app/config/app_config.dart';
import 'package:yumi/app/config/business_logic_strategy.dart';

class SCGlobalConfig {
  static String get apiHost => AppConfig.current.apiHost;
  static String get imgHost => AppConfig.current.imgHost;
  static String get privacyAgreementUrl => AppConfig.current.privacyAgreementUrl;
  static String get userAgreementUrl => AppConfig.current.userAgreementUrl;

  // 以下URL从AppConfig获取
  static String get anchorAgentUrl => AppConfig.current.anchorAgentUrl;
  static String get hostCenterUrl => AppConfig.current.hostCenterUrl;
  static String get bdCenterUrl => AppConfig.current.bdCenterUrl;
  static String get bdLeaderUrl => AppConfig.current.bdLeaderUrl;
  static String get coinSellerUrl => AppConfig.current.coinSellerUrl;
  static String get adminUrl => AppConfig.current.adminUrl;
  static String get agencyCenterUrl => AppConfig.current.agencyCenterUrl;
  static String get gamesKingUrl => AppConfig.current.gamesKingUrl;

  // 应用下载链接需要根据Flavor调整
  static String get appDownloadUrlGoogle => AppConfig.current.appDownloadUrlGoogle;
  static String get appDownloadUrlApple => AppConfig.current.appDownloadUrlApple;

  ///语言
  static String lang = "en";

  ///设备号
  static String imei = "";

  ///版本
  static String version = "1.0.0";
  static String build = "1";
  static String model = "SM-G9550";
  static String sysVersion = "9";
  static int sdkInt = 28;

  ///高于这个值才播放特效，避免低性能手机卡顿
  static int maxSdkNoAnim = 27;

  ///渠道SocialChat
  static String channel = "Google";
  static String origin = "LIKEI";
  static String originChild = "LIKEI";

  static String get tencentImAppid => AppConfig.current.tencentImAppid;
  static String get agoraRtcAppid => AppConfig.current.agoraRtcAppid;

  static num get gameAppid => AppConfig.current.gameAppid;
  static String get gameAppChannel => AppConfig.current.gameAppChannel;

  ///全服广播大群
  static String get bigBroadcastGroup => AppConfig.current.bigBroadcastGroup;

  static String get imAdmin => AppConfig.current.imAdmin;
  static const Set<String> _extraSystemUserIds = {"yuminotice"};

  static String _normalizeConversationUserId(String conversationId) {
    return conversationId.startsWith("c2c_")
        ? conversationId.replaceFirst("c2c_", "")
        : conversationId;
  }

  static Set<String> get systemUserIds {
    return {
      "administrator",
      _normalizeConversationUserId(imAdmin),
      ..._extraSystemUserIds,
    }.where((element) => element.isNotEmpty).toSet();
  }

  static Set<String> get systemConversationIds {
    return {
      "administrator",
      ...systemUserIds
          .where((element) => element != "administrator")
          .map((element) => "c2c_$element"),
    };
  }

  static String get primarySystemUserId => _normalizeConversationUserId(imAdmin);
  static String get primarySystemConversationId => "c2c_$primarySystemUserId";

  static bool isSystemConversationId(String? conversationId) {
    if (conversationId == null || conversationId.isEmpty) {
      return false;
    }
    return systemConversationIds.contains(conversationId);
  }

  static bool isSystemUserId(String? userId) {
    if (userId == null || userId.isEmpty) {
      return false;
    }
    return systemUserIds.contains(userId);
  }

  ///财富榜单
  static String get wealthRankUrl => AppConfig.current.wealthRankUrl;

  ///魅力榜
  static String get charmRankUrl => AppConfig.current.charmRankUrl;

  ///房间榜单
  static String get roomRankUrl => AppConfig.current.roomRankUrl;

  ///邀请新用户活动链接
  static String get inviteNewUserUrl => AppConfig.current.inviteNewUserUrl;

  ///是否在审核
  static bool? _isReviewOverride;
  static bool get isReview => _isReviewOverride ?? AppConfig.current.isReview;
  static set isReview(bool value) => _isReviewOverride = value;

  ///礼物特效开关
  static bool _isGiftSpecialEffects = true;
  static bool get isGiftSpecialEffects => _isGiftSpecialEffects;
  static set isGiftSpecialEffects(bool value) => _isGiftSpecialEffects = value;

  ///入场秀
  static bool _isEntryVehicleAnimation = true;
  static bool get isEntryVehicleAnimation => _isEntryVehicleAnimation;
  static set isEntryVehicleAnimation(bool value) => _isEntryVehicleAnimation = value;

  ///全局飘屏
  static bool _isFloatingAnimationInGlobal = true;
  static bool get isFloatingAnimationInGlobal => _isFloatingAnimationInGlobal;
  static set isFloatingAnimationInGlobal(bool value) => _isFloatingAnimationInGlobal = value;

  ///幸运礼物特效开关
  static bool _isLuckGiftSpecialEffects = true;
  static bool get isLuckGiftSpecialEffects => _isLuckGiftSpecialEffects;
  static set isLuckGiftSpecialEffects(bool value) => _isLuckGiftSpecialEffects = value;

  /// 获取当前业务逻辑策略
  static BusinessLogicStrategy get businessLogicStrategy {
    return AppConfig.current.businessLogicStrategy;
  }
}
