// RNFraudProtection.m

#import "RNFraudProtection.h"
#import <FraudProtection/FraudProtection-Swift.h>

@implementation RNFraudProtection

RCT_EXPORT_MODULE()

RCT_EXPORT_METHOD(start:(NSString *)instanceId baseUrl:(NSString *)baseUrl)
{
    if (baseUrl != nil) {
        [FraudProtection  startWithInstanceId:instanceId baseUrl:baseUrl];
    } else {
        [FraudProtection  startWithInstanceId:instanceId];
    }
}

RCT_EXPORT_METHOD(stop)
{
    [FraudProtection stop];
}

RCT_EXPORT_METHOD(send:(NSString *)pageId)
{
    [FraudProtection sendWithPageId:pageId];
}

// RCTResponseSenderBlock can not be null so need to expose two send method
RCT_EXPORT_METHOD(sendWithCallback:(NSString *)pageId callback:(RCTResponseSenderBlock)callback)
{
   [FraudProtection sendWithPageId:pageId sendResponse:^(NSDictionary<NSString *,id> *data, NSString *error) {
       if (data) {
           callback(@[[NSNull null], data]);
       } else {
           callback(@[error, [NSNull null]]);
       }
   }];
}

RCT_EXPORT_METHOD(getSessionId:(RCTResponseSenderBlock)callback)
{
    callback(@[[NSString stringWithFormat:@"%@", [FraudProtection getSessionId]]]);
}

RCT_EXPORT_METHOD(getAttributes:(RCTResponseSenderBlock)callback)
{
    NSDictionary<NSString *, id> *data = [FraudProtection getAttributes];
    if (data != nil) {
        callback(@[[FraudProtection getAttributes]]);
    } else {
        callback(@[[NSNull null]]);
    }
}

@end
