#import "RCTNativeNetworkModule.h"
#import "react_native_prestoplay-Swift.h"

@interface RCTNativeNetworkModule ()
@property (nonatomic, strong) RCTNativeNetworkModuleSwift *instance;
@end

@implementation RCTNativeNetworkModule
+ (NSString *)moduleName {
    return @"NativeNetworkModule";
}

- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params {
    return std::make_shared<facebook::react::NativeNetworkModuleSpecJSI>(params);
}

- (void)initialize {
    self.instance = [[RCTNativeNetworkModuleSwift alloc] init];
}


- (void)completeRequest:(nonnull NSString *)requestId url:(nonnull NSString *)url headers:(nonnull NSDictionary *)headers body:(nonnull NSString *)body resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
    [self.instance completeRequest:requestId url:url headers:headers body:body resolve:^(){ resolve(nil); } reject:^(NSString* prestoPlayErrorJson){ reject(nil, prestoPlayErrorJson, nil);}];
}

- (void)completeResponse:(nonnull NSString *)responseId headers:(nonnull NSDictionary *)headers body:(nonnull NSString *)body resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
    [self.instance completeResponse:responseId headers:headers body:body resolve:^(){ resolve(nil); } reject:^(NSString* prestoPlayErrorJson){ reject(nil, prestoPlayErrorJson, nil);}];
}

@end
