//
//  LSReserveSurvey+RCTLSSweepsCoordinator.m
//  ReactLightspeedSDK
//
//  Created by marc matta on 12/7/16.
//  Copyright © 2016 com.lightspeed. All rights reserved.
//

#import "RCTLSSweepsCoordinator.h"
#import <LightspeedSDK/LightspeedSDK-Swift.h>
#import "LSSweepsWinners+RCTNativeModel.h"

@implementation RCTLSSweepsCoordinator
RCT_EXPORT_MODULE(LSSweepsCoordinator);

static LSSweepsCoordinator *sharedInstance;
+ (LSSweepsCoordinator *)sharedInstance {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [LSSweepsCoordinator new];
    });
    
    return sharedInstance;
}

RCT_REMAP_METHOD(getSweepsWinners, resolver:(RCTPromiseResolveBlock)resolver rejecter:(RCTPromiseRejectBlock)rejecter) {
    [[RCTLSSweepsCoordinator sharedInstance] getSweepsWinners:^(LSSweepsWinners * _Nullable sweepsWinners, NSError * _Nullable error) {
        if (error) {
            rejecter([@(error.code) stringValue], error.localizedFailureReason, error);
        }else {
            resolver([sweepsWinners reactNativeRepresentation]);
        }
    }];
}

@end
