#import "ScanbotBarcodeSdkPluginResultDelegate.h"

@implementation ScanbotBarcodeSdkPluginResultDelegate {
    RCTPromiseResolveBlock resolveBlock;
    RCTPromiseRejectBlock rejectBlock;
}

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

- (void)didRejectPromise:(SBErrorResponse * _Nonnull)error {
    rejectBlock([@(error.code) stringValue], error.message, nil);
}

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

@end
