import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:package_info_plus/package_info_plus.dart';

const String kSmPlayerVersionDefine = String.fromEnvironment('SMPLAYER_VERSION');
const String kSmPlayerVersionFallback = '0.2.7';

final appVersionProvider = FutureProvider<String>(
  (ref) => getSmPlayerVersion(),
);

Future<String> getSmPlayerVersion() async {
  final configuredVersion = kSmPlayerVersionDefine.trim();
  if (configuredVersion.isNotEmpty) return configuredVersion;

  try {
    final info = await PackageInfo.fromPlatform();
    final version = info.version.trim();
    if (version.isNotEmpty) return version;
  } catch (_) {}
  return kSmPlayerVersionFallback;
}
