#import "RNProxyDelegate.h"

@implementation RNProxyDelegate {
    RCTPromiseResolveBlock resolveBlock;
    RCTPromiseRejectBlock rejectBlock;
}

- (instancetype)initWithResolveBlock:(RCTPromiseResolveBlock)resolve andRejectBlock:(RCTPromiseRejectBlock)reject {
    self = [super init];
    if (self) {
        resolveBlock = resolve;
        rejectBlock = reject;
    }
    return self;
}

- (void)didRejectPromise:(NSDictionary<NSString *,id> * _Nonnull)error {
    NSString* message = @"An unexpected error has occured";
    if([error objectForKey:@"message"]){
        message = [error objectForKey:(@"message")];
    }
    rejectBlock(@"ScanbotSDKError", message, nil);
}

- (void)didResolvePromise:(NSDictionary<NSString *,id> * )result {
    resolveBlock(result);
}

@end
