// Auto generated by Craby. DO NOT EDIT.
#import "CxxHwpjsModule.hpp"
#import <ReactCommon/CxxTurboModuleUtils.h>
#include <string>

@interface HwpjsModuleProvider : NSObject
@end

@implementation HwpjsModuleProvider

+ (void)load {
  const char *cDataPath = [[self getDataPath] UTF8String];
  std::string dataPath(cDataPath);

  craby::hwpjs::modules::CxxHwpjsModule::dataPath = dataPath;

  facebook::react::registerCxxModuleToGlobalModuleMap(
      craby::hwpjs::modules::CxxHwpjsModule::kModuleName,
      [](std::shared_ptr<facebook::react::CallInvoker> jsInvoker) {
        return std::make_shared<craby::hwpjs::modules::CxxHwpjsModule>(jsInvoker);
      });
}

+ (NSString *)getDataPath {
  NSString *appGroupID = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppGroupID"];
  NSString *dataPath = nil;

  if (appGroupID != nil) {
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSURL *containerURL = [fileManager containerURLForSecurityApplicationGroupIdentifier:appGroupID];

    if (containerURL == nil) {
      throw [NSException exceptionWithName:@"CrabyInitializationException"
                                    reason:[NSString stringWithFormat:@"Invalid AppGroup ID: %@", appGroupID]
                                  userInfo:nil];
      } else {
        dataPath = [containerURL path];
      }
  } else {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true);
    dataPath = [paths firstObject];
  }

  return dataPath;
}

@end
