import 'package:flyinsono/architecture/states/states.dart';
import 'package:install_plugin_custom/install_plugin_custom.dart';
import 'package:url_launcher/url_launcher.dart';

class UpgradeHelper {
  // 读编译时环境变量，判断是否是 Google 商店版
  static const UPGRADE_METHOD =
      String.fromEnvironment("UPGRADE_METHOD", defaultValue: "Manual");

  // Google 商店版
  static const bool isUpgradeByGoogle = UPGRADE_METHOD == "Google";

  static Future<String> installApk(String filePath, String appId) async {
    return InstallPluginCustom.installApk(filePath, appId);
  }

  static void openGooglePlay() async {
    final String googlePlayUrl = "market://details?id=com.vinno.flyinsono.next";
    final String webUrl =
        "https://play.google.com/store/apps/details?id=com.vinno.flyinsono.next";
    if (await canLaunchUrl(Uri.parse(googlePlayUrl))) {
      await launchUrl(Uri.parse(googlePlayUrl));
    } else {
      launchUrl(Uri.parse(webUrl));
    }
  }

  static void openAppStore() async {
    final String appStoreArea = Store.app.isCurrChinese ? "cn" : "us";
    final String appStorePlayUrl =
        "https://apps.apple.com/$appStoreArea/app/id1501133381";
    await launchUrl(Uri.parse(appStorePlayUrl));
  }
}
