import 'dart:ffi';
import 'dart:io' show Platform;

typedef CreateInstanceNative = Pointer<Void> Function();

class TMGLoadDynamic {
  static TMGLoadDynamic? _instance = null;
  late DynamicLibrary? gmeSdkLib = null;

  TMGLoadDynamic() {
    if (gmeSdkLib == null) {
      if (Platform.isIOS) {
        gmeSdkLib = DynamicLibrary.process();
      } else if (Platform.isAndroid) {
        gmeSdkLib = DynamicLibrary.open("libgmesdkv2.so");
      } else {
        throw UnsupportedError("Unsupported platform");
      }
    }
  }

  static TMGLoadDynamic GetInstance() {
    if (_instance == null) {
      _instance = TMGLoadDynamic();
    }
    return _instance!;
  }

  DynamicLibrary? GetGmeSdkLib() {
    return gmeSdkLib!;
  }
}
