import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:location/data/consts/web_url.dart';
import 'package:wechat_kit/wechat_kit.dart';
import '../../data/consts/build_config.dart';

class WechatHelper {
  WechatHelper._();

  static final appId = WechatConfig.wechatAppId;
  static final String universalLink = WebUrl.shareUrl;

  static Future<void> registerApp() {
    return WechatKitPlatform.instance
        .registerApp(appId: appId, universalLink: universalLink)
        .then((_) {
      debugPrint('微信注册成功');
    }).catchError((error) {
      debugPrint('微信注册失败: $error');
    });
  }

  static Future<void> shareImageToWechat({
    required int scene,
    Uint8List? imageData,
    Uri? imageUri,
  }) async {
    return WechatKitPlatform.instance.shareImage(
      scene: scene,
      imageData: imageData,
      imageUri: imageUri,
    );
  }

  static Future<void> shareTextToWechat({
    required int scene,
    required String text,
  }) async {
    return WechatKitPlatform.instance.shareText(
      scene: scene,
      text: text,
    );
  }

  static Future<void> shareUrlToWechat({
    required int scene,
    required String webpageUrl,
    String? title,
    String? description,
    Uint8List? thumbData,
  }) async {
    return WechatKitPlatform.instance.shareWebpage(
        scene: scene,
        webpageUrl: webpageUrl,
        title: title,
        thumbData: thumbData,
        description: description);
  }

  static Future<bool> isInstalled() {
    return WechatKitPlatform.instance.isInstalled();
  }
}
