//
//  HanselTrackerRn.m
//  AwesomeProject
//
//  Created by Rajeev Rajeshuni on 22/10/19.
//  Copyright © 2019 Facebook. All rights reserved.
//

#import "HanselTrackerRn.h"

@implementation HanselTrackerRn {
    BOOL hasListeners;
}

- (NSArray<NSString *> *)supportedEvents {
    @try {
        return @[@"HanselRequestSynced",@"HanselActionPerformed",@"HanselInternalEvent",@"HanselDeepLinkListener"];
    } @catch (NSException *exception) {
        NSLog(@"Hansel error: Exception caught in supportedEvents method in HanselRn bridge.");
    }
}

- (void)getHanselData:(NSString* _Nonnull)eventName andVendor:(NSString* _Nonnull)vendor withProperties:(NSDictionary*_Nullable)properties callback:(RCTResponseSenderBlock)callback {
    @try {
        [HanselRnUtils returnResult:[HanselTracker getHanselData:eventName andVendor:vendor withProperties:properties] withCallback:callback];
    } @catch (NSException *exception) {
        NSLog(@"Hansel error: Exception caught in getHanselData method in HanselTrackerRn bridge.");
    }
}

- (void)isUsedInMap:(NSString* _Nonnull)event andVendor:(NSString* _Nonnull)vendor withProperties:(NSDictionary* _Nullable)properties callback:(RCTResponseSenderBlock)callback {
    @try {
        [HanselRnUtils returnResult:[NSNumber numberWithBool:[HanselTracker isUsedInMap:event andVendor:vendor withProperties:properties]] withCallback:callback];
    } @catch (NSException *exception) {
        NSLog(@"Hansel error: Exception caught in isUsedInMap method in HanselTrackerRn bridge.");
    }
}

- (void)logEvent:(NSString* _Nonnull)eventName vendor:(NSString* _Nonnull)vendor hanselProperties:(NSDictionary* _Nullable)hanselProperties callback:(RCTResponseSenderBlock)callback {
    @try {
        [HanselRnUtils returnResult:[HanselTracker logEvent:eventName andVendor:vendor withProperties:hanselProperties] withCallback:callback];
    } @catch (NSException *exception) {
        NSLog(@"Hansel error: Exception caught in logEvent method in HanselTrackerRn bridge.");
    }
}

- (void)startRequestSyncEvents {
    @try {
        [[HanselRnSyncStateListener sharedInstance] startSyncEvents];
    } @catch (NSException *exception) {
        NSLog(@"Hansel error: Exception caught in startRequestSSyncEvents method in HanselRn bridge.");
    }
}

- (void)stopRequestSyncEvents {
    @try {
        [[HanselRnSyncStateListener sharedInstance] stopSyncEvents];
    } @catch (NSException *exception) {
        NSLog(@"Hansel error: Exception caught in stopRequestSyncEvents method in HanselRn bridge.");
    }
}

- (void)registerHanselTrackerListener {
    @try {
        [[HanselRnEventsListener sharedInstance] registerListener];
    } @catch (NSException *exception) {
        NSLog(@"Hansel error: Exception caught in registerListener method in HanselTrackerRn bridge.");
    }
}

- (void)registerHanselDeeplinkListener {
    @try {
        [[HanselRnActionListener sharedInstance] registerHanselDeeplinkListener];
    } @catch (NSException *exception) {
        NSLog(@"Hansel error: Exception caught in registerHanselActionListenerForAction method in HanselRn bridge.");
    }
}

- (void)registerHanselActionListenerWithActionName:(NSString*)actionName {
    @try {
        [[HanselRnActionListener sharedInstance] registerHanselActionListenerForAction:actionName];
    } @catch (NSException *exception) {
        NSLog(@"Hansel error: Exception caught in removeHanselActionListenerForAction method in HanselRn bridge.");
    }
}

- (void)removeHanselActionListenerForAction:(NSString*)actionName {
    @try {
        [[HanselRnActionListener sharedInstance] removeHanselActionListenerForAction:actionName];
    } @catch (NSException *exception) {
        NSLog(@"Hansel error: Exception caught in removeHanselActionListenerForAction method in HanselRn bridge.");
    }
}


- (void)deRegisterListener {
    @try {
        [[HanselRnEventsListener sharedInstance] deRegisterListener];
    } @catch (NSException *exception) {
        NSLog(@"Hansel error: Exception caught in deRegisterListener method in HanselTrackerRn bridge.");
    }
}

@end

