import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:package_info_plus/package_info_plus.dart';

abstract class PlatformInfo {
  static bool get isWeb => kIsWeb;

  static bool get isLinux => !kIsWeb && Platform.isLinux;

  static bool get isInFlatpak =>
      kIsWeb ? false : Platform.environment['FLATPAK_ID'] != null;

  static bool get isWindows => !kIsWeb && Platform.isWindows;

  static bool get isMacOS => !kIsWeb && Platform.isMacOS;

  static bool get isIOS => !kIsWeb && Platform.isIOS;

  static bool get isAndroid => !kIsWeb && Platform.isAndroid;

  static bool get isMobile => isAndroid || isIOS;

  // Not first tier supported platform
  static bool get isBetaDesktop => isWindows || isLinux;

  static bool get isDesktop => isLinux || isWindows || isMacOS;

  static bool get useTouchscreen => !isMobile;

  static bool get canCacheImage => isAndroid || isIOS || isMacOS;

  static bool get canRecord => (isMobile || isMacOS);

  static bool get canPushNotification => isAndroid || isIOS || isMacOS;

  static Future<String> getVersion() async {
    var version = kIsWeb ? 'Web' : 'Unknown';
    try {
      version = (await PackageInfo.fromPlatform()).version;
    } catch (_) {}
    return version;
  }
}
