#import "RNRedirapp.h"
@import Redirapp;

@implementation RNRedirapp

RCT_EXPORT_METHOD(init:(NSString *)token
                  resolver:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject)
{
    [Redirapp init:token];
}

RCT_EXPORT_METHOD(logPurchase:(NSDictionary *)request
                  resolver:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject)
{
    NSString *amountString = [RCTConvert NSString:request[@"amount"]];
    double amount = [amountString doubleValue];
    NSString *sku = [RCTConvert NSString:request[@"sku"]];
    [Redirapp logPurchaseWithAmount:amount sku:sku];
}

RCT_EXPORT_METHOD(logPurchaseWithCurrency:(NSDictionary *)request
                  resolver:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject)
{
    NSString *amountString = [RCTConvert NSString:request[@"amount"]];
    double amount = [amountString doubleValue];
    NSString *sku = [RCTConvert NSString:request[@"sku"]];
    NSString *currency = [RCTConvert NSString:request[@"currency"]];
    [Redirapp logPurchaseWithAmount:amount currency:currency sku:sku];
}

- (dispatch_queue_t)methodQueue
{
    return dispatch_get_main_queue();
}

RCT_EXPORT_MODULE()

@end
