#import "Responsys.h"

static NSString *deviceId = nil;
static NSString *userId = nil;
static Boolean isLocation = true;

@implementation Responsys

RCT_EXPORT_MODULE()

RCT_EXPORT_METHOD(sampleMethod:(NSString *)stringArgument numberParameter:(nonnull NSNumber *)numberArgument callback:(RCTResponseSenderBlock)callback)
{
    // TODO: Implement some actually useful functionality
	callback(@[[NSString stringWithFormat: @"numberArgument: %@ stringArgument: %@", numberArgument, stringArgument]]);
}

RCT_EXPORT_METHOD(fetchMessagesForMessageCenter:(NSString *)messageCenter:(RCTResponseSenderBlock)callback){
    __block NSArray *messageList = nil;
    __block NSString *jsonString = nil;
    __block NSString *errorMessage = nil;
    __weak typeof (self) weakSelf = self;
    [[PushIOManager sharedInstance] fetchMessagesForMessageCenter:messageCenter CompletionHandler:^(NSError *error, NSArray *messages) {
        if (nil != error) {
            switch (error.code) {
                case PIOErrorCodeInvalidURL:
                    errorMessage = @"Message URL is invalid, check the provided message center name and retry.";
                    break;
                case PIOErrorCodeNoNetwork:
                    errorMessage = @"No Network available, check the device network and try again.";
                    break;
                case PIOErrorCodeMaximumRetryReached:
                    errorMessage = @"Maximum retrial for message fetch has reached, that's due to because response received was either 500 or 429.";
                    break;
                case PIOErrorCodeEmptyResponse:
                    errorMessage = @"Message list is empty.";
                    break;
                case PIOErrorCodeInvalidPayload:
                    errorMessage = @"Invalid response received.";
                    break;
                case PIOHTTTPStatusCodeInvalidAppOrAccountToken:
                    errorMessage = error.userInfo[@"ErrorStatus"];
                    break;
                case PIOHTTTPStatusCodeMCDisabled:
                    errorMessage = error.userInfo[@"ErrorStatus"];
                    break;
                case PIOHTTTPStatusCodeMCFailure:
                    errorMessage = error.userInfo[@"ErrorStatus"];
                    break;
                default:
                    errorMessage = error.description;
                    break;
            }
            [weakSelf showAlert:errorMessage];
        }else{
            messageList = messages;
        }
    }];
    
    NSEnumerator *arrenum = [messageList objectEnumerator];
    id cobj;
    NSMutableArray *myArray = [NSMutableArray array];
//    while ( cobj = [arrenum nextObject] ) {
//        NSLog(@"isi pesan --> %@", cobj);
//        PIOMCMessage *mcMessage = cobj;
//        NSLog(@"Message Subject: %@, %@, %@, %@, %@, %@, %@, %@, %@, %@", mcMessage.messageID, mcMessage.message, mcMessage.subject, mcMessage.sentTimestamp, mcMessage.expiryTimestamp, mcMessage.messageCenterName, mcMessage.iconURL, mcMessage.deeplinkURL, mcMessage.richMessageHTML, mcMessage.richMessageURL);
//        NSMutableDictionary *bookListing = [NSMutableDictionary dictionary];
//        [bookListing setObject: mcMessage.messageID  forKey: @"id"];
//        if(mcMessage.message == nil)
//            [bookListing setObject: @"" forKey: @"message"];
//        else
//            [bookListing setObject: mcMessage.message forKey: @"message"];
//        if(mcMessage.subject == nil)
//            [bookListing setObject: @""  forKey: @"subject"];
//        else
//            [bookListing setObject: mcMessage.subject  forKey: @"subject"];
//        if(mcMessage.sentTimestamp == nil)
//            [bookListing setObject: @""  forKey: @"sentTimestamp"];
//        else
//            [bookListing setObject: mcMessage.sentTimestamp  forKey: @"sentTimestamp"];
//        if(mcMessage.expiryTimestamp == nil)
//            [bookListing setObject: @"" forKey:@"expiryTimestamp"];
//        else
//            [bookListing setObject: mcMessage.expiryTimestamp forKey:@"expiryTimestamp"];
//        if(mcMessage.messageCenterName == nil)
//            [bookListing setObject: @"" forKey:@"messageCenterName"];
//        else
//            [bookListing setObject: mcMessage.messageCenterName forKey:@"messageCenterName"];
//        if(mcMessage.iconURL == nil)
//            [bookListing setObject: @""  forKey: @"iconUrl"];
//        else
//            [bookListing setObject: mcMessage.iconURL  forKey: @"iconUrl"];
//        if(mcMessage.deeplinkURL == nil)
//            [bookListing setObject: @"" forKey:@"deeplinkURL"];
//        else
//            [bookListing setObject: mcMessage.deeplinkURL forKey:@"deeplinkURL"];
//        if(mcMessage.richMessageHTML == nil)
//            [bookListing setObject: @"" forKey:@"richMessageHTML"];
//        else
//            [bookListing setObject: mcMessage.richMessageHTML forKey:@"richMessageHTML"];
//        if(mcMessage.richMessageURL == nil)
//            [bookListing setObject: @"" forKey:@"richMessageURL"];
//        else
//            [bookListing setObject: mcMessage.richMessageURL forKey:@"richMessageURL"];
//        [myArray addObject:bookListing];
//    }
//    for (PIOMCMessage *mcMessage in messageList) {
//        NSLog(@"Message Subject: %@, %@, %@, %@, %@, %@, %@, %@, %@, %@", mcMessage.messageID, mcMessage.message, mcMessage.subject, mcMessage.sentTimestamp, mcMessage.expiryTimestamp, mcMessage.messageCenterName, mcMessage.iconURL, mcMessage.deeplinkURL, mcMessage.richMessageHTML, mcMessage.richMessageURL);
//        NSMutableDictionary *bookListing = [NSMutableDictionary dictionary];
//        [bookListing setObject: mcMessage.messageID  forKey: @"id"];
//        [bookListing setValue: mcMessage.message forKey: @"message"];
//        [bookListing setValue: mcMessage.subject  forKey: @"subject"];
//        [bookListing setValue: mcMessage.sentTimestamp  forKey: @"sentTimestamp"];
//        [bookListing setValue: mcMessage.expiryTimestamp forKey:@"expiryTimestamp"];
//        [bookListing setValue: mcMessage.messageCenterName forKey:@"messageCenterName"];
//        [bookListing setValue: mcMessage.iconURL  forKey: @"iconUrl"];
//        [bookListing setValue: mcMessage.deeplinkURL forKey:@"deeplinkURL"];
//        [bookListing setValue: mcMessage.richMessageHTML forKey:@"richMessageHTML"];
//        [bookListing setValue: mcMessage.richMessageURL forKey:@"richMessageURL"];
//        [myArray addObject:bookListing];
//    }
    
    NSMutableDictionary *bookListing = [NSMutableDictionary dictionary];
            [bookListing setObject: @"ABElqDXnWsraJx5n_h14oakTyOoucR3S4qXJ2wncw__6_m4q8px8E-8o_IROzoEbH1DuHlLiBDDbDDociq382t"  forKey: @"id"];
            [bookListing setObject: @"(check interactive buttons if working), sekarang masuk ga ke table pesan?" forKey: @"message"];
            [bookListing setObject: @"subject inbox msg" forKey: @"subject"];
            [bookListing setObject: @"2019-09-30 07:14:11 +0000"  forKey: @"sentTimestamp"];
            [bookListing setObject: @"2019-12-31 15:59:00 +0000" forKey:@"expiryTimestamp"];
            [bookListing setObject: @"Primary" forKey:@"messageCenterName"];
            [bookListing setObject: @"url url"  forKey: @"iconUrl"];
            [bookListing setObject: @"url url" forKey:@"deeplinkURL"];
            [bookListing setObject: @"url url" forKey:@"richMessageHTML"];
            [bookListing setObject: @"url url" forKey:@"richMessageURL"];
            [myArray addObject:bookListing];
    NSLog(@"MyArray --> %@",myArray);
    callback(@[errorMessage, bookListing]);
}

//RCT_EXPORT_METHOD(getRegisteredCategories:(RCTResponseSenderBlock)callback){
//    [[PushIOManager sharedInstance] getRegisteredCategories]
//}

RCT_EXPORT_METHOD(fetchRichContentForMessage:(NSString *)msgID){
    [[PushIOManager sharedInstance] fetchRichContentForMessage:msgID CompletionHandler:^(NSError *error, NSString *messageID, NSString *content) {
        NSLog(@"MessageID: %@ RichContent: %@ Error: %@", messageID, content, error);
    }];
}

-(void) showAlert:(NSString *)message{
    dispatch_async(dispatch_get_main_queue(), ^{
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Message" message:message preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {}];
        [alert addAction:defaultAction];
        //    [self presentViewController:alert animated:YES completion:nil];
    });
}

RCT_EXPORT_METHOD(setPreference:(NSString *)Item:(NSString *)isi:(NSString *)type){
    if([type  isEqual: @"boolean"]){
        [[PushIOManager sharedInstance] setBoolPreference:isi forKey:Item];
    }
    if([type  isEqual: @"string"]){
        [[PushIOManager sharedInstance] setStringPreference:isi forKey:Item];
    }
    if([type  isEqual: @"number"]){
        [[PushIOManager sharedInstance] setNumberPreference:isi forKey:Item];
    }
}

RCT_EXPORT_METHOD(getPreference:(NSString *)Item:(RCTResponseSenderBlock)callback){
    PIOPreference *test = [[PushIOManager sharedInstance] getPreference:Item];
    NSMutableDictionary *bookListing = [NSMutableDictionary dictionary];
    NSString *tipe = nil;
    if(test.type == 0){
        tipe = @"STRING";
    }
    if(test.type == 1){
        tipe = @"NUMBER";
    }
    if(test.type == 2){
        tipe = @"BOOLEAN";
    }
    [bookListing setObject: test.key  forKey: @"mKey"];
    [bookListing setObject: test.label  forKey: @"mLabel"];
    [bookListing setObject: tipe forKey: @"mType"];
    [bookListing setObject: test.value  forKey: @"mValue"];
    
    callback(@[[NSNull null], bookListing]);
}

RCT_EXPORT_METHOD(getPreferences:(RCTResponseSenderBlock)callback){
    NSArray *newsPreference = [[PushIOManager sharedInstance] getPreferences];
    NSLog(@"getPreferences value --> %@",newsPreference);
    NSEnumerator *arrenum = [newsPreference objectEnumerator];
    id cobj;
    NSMutableArray *myArray = [NSMutableArray array];
    while ( cobj = [arrenum nextObject] ) {
        NSLog(@"isi preference --> %@", cobj);
        PIOPreference *test = cobj;
        NSMutableDictionary *bookListing = [NSMutableDictionary dictionary];
        NSString *tipe = nil;
        if(test.type == 0){
            tipe = @"STRING";
        }
        if(test.type == 1){
            tipe = @"NUMBER";
        }
        if(test.type == 2){
            tipe = @"BOOLEAN";
        }
        [bookListing setObject: test.key  forKey: @"mKey"];
        [bookListing setObject: test.label  forKey: @"mLabel"];
        [bookListing setObject: tipe forKey: @"mType"];
        [bookListing setObject: test.value  forKey: @"mValue"];
        NSLog(@"Hasilnya --> %@, %@, %lu, %@", test.key, test.label, (unsigned long)test.type, test.value);
        [myArray addObject:bookListing];
    }
    
    NSLog(@"isi json-nya --> %@", myArray);

    callback(@[[NSNull null], myArray]);
}

RCT_EXPORT_METHOD(setBadgeCount:(NSString *)badge){
    [[PushIOManager sharedInstance] setBadgeCount:badge completionHandler:^(NSError *error, NSString *response) {
        if (nil == error) {
            // Badge count set and synced successfully.
        } else {
            // Error occurred, unable to sync and set badge count
            // Handle error. If required you can set app badge count locally by calling iOS API [[UIApplication sharedApplication] setApplicationIconBadgeNumber:2];
            NSLog(@"Unable to set badge count, reason: %@", error.description);
        }
    }];
}

RCT_EXPORT_METHOD(resetBadgeCountWithCompletionHandler:(RCTResponseSenderBlock)callback){
    NSError *error = nil;
    [[PushIOManager sharedInstance] resetBadgeCountWithCompletionHandler:^(NSError *error, NSString *response) {
        if (nil == error) {
            // Badge count set and synced successfully.
        } else {
            // Error occurred, unable to sync and set badge count
            // Handle error. If required you can set app badge count locally by calling iOS app [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
            NSLog(@"Unable to reset the badge count, reason: %@", error.description);
        }
    }];
}

RCT_EXPORT_METHOD(getBadgeCount:(RCTResponseSenderBlock)callback){
    callback(@[[NSNull null], @([[PushIOManager sharedInstance] getBadgeCount])]);
}

RCT_EXPORT_METHOD(declarePreference:(NSString *)Item forIsi:(NSString *)isi forType:(NSString *)type){
    NSError *error = nil;
    NSLog(@"set declarePreference bridge");
    if([type  isEqual: @"boolean"]){
        [[PushIOManager sharedInstance] declarePreference:Item label:isi type:PIOPreferenceTypeBoolean error:&error];
        if (error != nil) {
            // Examine error
        }
    }
    if([type  isEqual: @"string"]){
        [[PushIOManager sharedInstance] declarePreference:Item label:isi type:PIOPreferenceTypeString error:&error];
        if (error != nil) {
            // Examine error
        }
    }
    if([type  isEqual: @"number"]){
        [[PushIOManager sharedInstance] declarePreference:Item label:isi type:PIOPreferenceTypeNumeric error:&error];
        if (error != nil) {
            // Examine error
        }
    }
}

RCT_EXPORT_METHOD(initializeApp:(NSString *)apiKey forAccountToken:(NSString *)accountToken){
    NSLog(@"initializeApp module");
    //------------------------------  Toggle Logging  --------------------------------//
    /*Default log level is set to Info. Refer to PushIOManager.h to know about other different log levels available.*/
    
#ifdef DEBUG
    [[PushIOManager sharedInstance] setLoggingEnabled:YES];
    [[PushIOManager sharedInstance] setLogLevel:PIOLogLevelVerbose];
#else
    [[PushIOManager sharedInstance] setLoggingEnabled:NO];
#endif
    
    //---------------------------- Configure and Register the SDK ------------------------//
    
    NSError *error = nil;
    
    [[PushIOManager sharedInstance] configureAndRegisterWithAPIKey:apiKey accountToken:accountToken completionHandler:^(NSError *error, NSString *response){
        if (nil == error){
            NSLog(@"Application registered successfully");
        }else{
            NSLog(@"Unable to configure and register, reason:%@",error.description);
        }
    }];
    
    //--------------------------- Register for Push with Responsys Backend ---------------------//
    /*The application is registered with Oracle Responsys Push backend without prompting for opt-in to push notifications.*/
    
    NSError *regTrackError = nil;
    
    [[PushIOManager sharedInstance] registerApp:&regTrackError completionHandler:^(NSError *regAppError, NSString *response)
     {
         if (nil == regAppError){
             NSLog(@"Application registered successfully!");
         }else{
             NSLog(@"Unable to register application, reason: %@", regAppError.description);
         }
     }];
    
    
    
    //------------------------------  Opt-in to Push Notifications ------------------------------//
    /*The user is prompted a dialogue to opt-in for push notifications. If the user chooses to opt-in ,the following sync event's permissions will include permissions needed for Push.
     If the user chooses to opt-out now, then inorder to opt-in to Push notifications in the future they will have to go to system settings -> notifications ,then select the application and use the toggle switch.*/
    
    [[PushIOManager sharedInstance] registerForAllRemoteNotificationTypes:^(NSError *error, NSString *deviceToken)
     {
         if (nil == error) {
             NSError *regTrackError = nil;
             [[PushIOManager sharedInstance] registerApp:&regTrackError completionHandler:^(NSError *regAppError, NSString *response)
              {
                  if (nil == regAppError){
                      NSLog(@"Application registered successfully!");
                  }else{
                      NSLog(@"Unable to register application, reason: %@", regAppError.description);
                  }
              }];
             if (nil == regTrackError) {
                 NSLog(@"Registration locally stored successfully.");
             }else{
                 NSLog(@"Unable to store registration, reason: %@", regTrackError.description);
             }
         }
     }];
    
    
    //------------------------------  Opt-in for location  ------------------------------//
    /*The user is prompted a dialogue to opt-in for location updates. If the user chooses to opt-in, the following sync with Responsys backend server will have updated value for permissions field now including 'location_active' . Furthermore all future syncs will have latitude and longitude values as a part of the sync event data unless they opt-out of it.*/
    
    [[PushIOManager sharedInstance] setDesiredLocationAccuracy:10.0];
    [[PushIOManager sharedInstance] setDistanceFilter:500];
    [[PushIOManager sharedInstance] startUpdatingLocationForPush];
}

//RCT_EXPORT_METHOD(initializeApp){
//    NSLog(@"initializeApp");
//    //------------------------------  Toggle Logging  --------------------------------//
//    /*Default log level is set to Info. Refer to PushIOManager.h to know about other different log levels available.*/
//
//#ifdef DEBUG
//    [[PushIOManager sharedInstance] setLoggingEnabled:YES];
//    [[PushIOManager sharedInstance] setLogLevel:PIOLogLevelVerbose];
//#else
//    [[PushIOManager sharedInstance] setLoggingEnabled:NO];
//#endif
//
//    //---------------------------- Configure and Register the SDK ------------------------//
//
//    NSString *apiKey = @"ABEvnYpCLWVqXrfE69HvQ8W5E";
//    NSString *accountToken = @"ABEqWKT9aENU0Sbr-iPuf9mY0";
//
//    NSError *error = nil;
//
//    [[PushIOManager sharedInstance] configureAndRegisterWithAPIKey:apiKey accountToken:accountToken completionHandler:^(NSError *error, NSString *response){
//        if (nil == error){
//            NSLog(@"Application registered successfully");
//        }else{
//            NSLog(@"Unable to configure and register, reason:%@",error.description);
//        }
//    }];
//
//    //--------------------------- Register for Push with Responsys Backend ---------------------//
//    /*The application is registered with Oracle Responsys Push backend without prompting for opt-in to push notifications.*/
//
//    NSError *regTrackError = nil;
//
//    [[PushIOManager sharedInstance] registerApp:&regTrackError completionHandler:^(NSError *regAppError, NSString *response)
//     {
//         if (nil == regAppError){
//             NSLog(@"Application registered successfully!");
//         }else{
//             NSLog(@"Unable to register application, reason: %@", regAppError.description);
//         }
//     }];
//
//
//
//    //------------------------------  Opt-in to Push Notifications ------------------------------//
//    /*The user is prompted a dialogue to opt-in for push notifications. If the user chooses to opt-in ,the following sync event's permissions will include permissions needed for Push.
//     If the user chooses to opt-out now, then inorder to opt-in to Push notifications in the future they will have to go to system settings -> notifications ,then select the application and use the toggle switch.*/
//
//    [[PushIOManager sharedInstance] registerForAllRemoteNotificationTypes:^(NSError *error, NSString *deviceToken)
//     {
//         if (nil == error) {
//             NSError *regTrackError = nil;
//             [[PushIOManager sharedInstance] registerApp:&regTrackError completionHandler:^(NSError *regAppError, NSString *response)
//              {
//                  if (nil == regAppError){
//                      NSLog(@"Application registered successfully!");
//                  }else{
//                      NSLog(@"Unable to register application, reason: %@", regAppError.description);
//                  }
//              }];
//             if (nil == regTrackError) {
//                 NSLog(@"Registration locally stored successfully.");
//             }else{
//                 NSLog(@"Unable to store registration, reason: %@", regTrackError.description);
//             }
//         }
//     }];
//
//
//    //------------------------------  Opt-in for location  ------------------------------//
//    /*The user is prompted a dialogue to opt-in for location updates. If the user chooses to opt-in, the following sync with Responsys backend server will have updated value for permissions field now including 'location_active' . Furthermore all future syncs will have latitude and longitude values as a part of the sync event data unless they opt-out of it.*/
//
//    [[PushIOManager sharedInstance] setDesiredLocationAccuracy:10.0];
//    [[PushIOManager sharedInstance] setDistanceFilter:500];
//    [[PushIOManager sharedInstance] startUpdatingLocationForPush];
//}


RCT_EXPORT_METHOD(registerApp:(NSString *)apiKey forAccountToken:(NSString *)accountToken){
    //------------------------------  Toggle Logging  --------------------------------//
    /*Default log level is set to Info. Refer to PushIOManager.h to know about other different log levels available.*/
    
#ifdef DEBUG
    [[PushIOManager sharedInstance] setLoggingEnabled:YES];
    [[PushIOManager sharedInstance] setLogLevel:PIOLogLevelVerbose];
#else
    [[PushIOManager sharedInstance] setLoggingEnabled:NO];
#endif
    
    //---------------------------- Configure and Register the SDK ------------------------//
    
    NSError *error = nil;
    
    [[PushIOManager sharedInstance] configureAndRegisterWithAPIKey:apiKey accountToken:accountToken completionHandler:^(NSError *error, NSString *response){
        if (nil == error){
            NSLog(@"Application registered successfully");
        }else{
            NSLog(@"Unable to configure and register, reason:%@",error.description);
        }
    }];
    
    //--------------------------- Register for Push with Responsys Backend ---------------------//
    /*The application is registered with Oracle Responsys Push backend without prompting for opt-in to push notifications.*/
    
    NSError *regTrackError = nil;
    
    [[PushIOManager sharedInstance] registerApp:&regTrackError completionHandler:^(NSError *regAppError, NSString *response)
     {
         if (nil == regAppError){
             NSLog(@"Application registered successfully!");
         }else{
             NSLog(@"Unable to register application, reason: %@", regAppError.description);
         }
     }];
    
    
    
    //------------------------------  Opt-in to Push Notifications ------------------------------//
    /*The user is prompted a dialogue to opt-in for push notifications. If the user chooses to opt-in ,the following sync event's permissions will include permissions needed for Push.
     If the user chooses to opt-out now, then inorder to opt-in to Push notifications in the future they will have to go to system settings -> notifications ,then select the application and use the toggle switch.*/
    
    [[PushIOManager sharedInstance] registerForAllRemoteNotificationTypes:^(NSError *error, NSString *deviceToken)
     {
         if (nil == error) {
             NSError *regTrackError = nil;
             [[PushIOManager sharedInstance] registerApp:&regTrackError completionHandler:^(NSError *regAppError, NSString *response)
              {
                  if (nil == regAppError){
                      NSLog(@"Application registered successfully!");
                  }else{
                      NSLog(@"Unable to register application, reason: %@", regAppError.description);
                  }
              }];
             if (nil == regTrackError) {
                 NSLog(@"Registration locally stored successfully.");
             }else{
                 NSLog(@"Unable to store registration, reason: %@", regTrackError.description);
             }
         }
     }];
    
    
    //------------------------------  Opt-in for location  ------------------------------//
    /*The user is prompted a dialogue to opt-in for location updates. If the user chooses to opt-in, the following sync with Responsys backend server will have updated value for permissions field now including 'location_active' . Furthermore all future syncs will have latitude and longitude values as a part of the sync event data unless they opt-out of it.*/
    
    [[PushIOManager sharedInstance] setDesiredLocationAccuracy:10.0];
    [[PushIOManager sharedInstance] setDistanceFilter:500];
    [[PushIOManager sharedInstance] startUpdatingLocationForPush];
    // Requests a device token from Apple
    [[PushIOManager sharedInstance] registerForAllRemoteNotificationTypes:^(NSError *error, NSString *deviceToken)
     {
         if (nil == error) {
             NSError *regTrackError = nil;
             [[PushIOManager sharedInstance] registerApp:&regTrackError completionHandler:^(NSError *regAppError, NSString *response)
              {
                  if (nil == regAppError){
                      NSLog(@"Application registered successfully!");
                  }else{
                      NSLog(@"Unable to register application, reason: %@", regAppError.description);
                  }
              }];
             if (nil == regTrackError) {
                 NSLog(@"Registration locally stored successfully.");
             }else{
                 NSLog(@"Unable to store registration, reason: %@", regTrackError.description);
             }
         }
     }];
    
    deviceId = [[PushIOManager sharedInstance] getDeviceID];
    //  [[PushIOManager sharedInstance] didFinishLaunchingWithOptions:launchOptions];
}

RCT_EXPORT_METHOD(getDeviceId:(RCTResponseSenderBlock)callback){
    deviceId = [[PushIOManager sharedInstance] getDeviceID];
    callback(@[[NSNull null], deviceId]);
}

RCT_EXPORT_METHOD(getUserId:(RCTResponseSenderBlock)callback){
    callback(@[[NSNull null], userId]);
}

RCT_EXPORT_METHOD(getRegisteredUserId:(RCTResponseSenderBlock)callback){
    userId = [[PushIOManager sharedInstance] getUserID];
    callback(@[[NSNull null], userId]);
}

RCT_EXPORT_METHOD(registerUserId:(NSString *) userId){
    [[PushIOManager sharedInstance] registerUserID:userId];
}

RCT_EXPORT_METHOD(unregisterUserId){
    [[PushIOManager sharedInstance] registerUserID:nil];
}

RCT_EXPORT_METHOD(setLoggingEnabled:(NSString *)isian){
    NSLog(@"setLogLevel to logLevel");
}

RCT_EXPORT_METHOD(setLogLevel:(NSString *)logLevel) {
    NSLog(@"setLogLevel to logLevel");
#ifdef DEBUG
    [[PushIOManager sharedInstance] setLoggingEnabled:YES];
    if([logLevel  isEqualToString:@"info"])
        [[PushIOManager sharedInstance] setLogLevel:PIOLogLevelInfo]; //PIOLogLevelWarn or PIOLogLevelError
    if([logLevel  isEqualToString:@"verbose"])
        [[PushIOManager sharedInstance] setLogLevel:PIOLogLevelVerbose]; //PIOLogLevelWarn or PIOLogLevelError
    if([logLevel  isEqualToString:@"debug"])
        [[PushIOManager sharedInstance] setLogLevel:PIOLogLevelDebug]; //PIOLogLevelWarn or PIOLogLevelError
    if([logLevel  isEqualToString:@"error"])
        [[PushIOManager sharedInstance] setLogLevel:PIOLogLevelError]; //PIOLogLevelWarn or PIOLogLevelError
    if([logLevel  isEqualToString:@"warn"])
        [[PushIOManager sharedInstance] setLogLevel:PIOLogLevelWarn]; //PIOLogLevelWarn or PIOLogLevelError
    if([logLevel  isEqualToString:@"assert"])
        [[PushIOManager sharedInstance] setLogLevel:PIOLogLevelNone]; //PIOLogLevelWarn or PIOLogLevelError
#else
    [[PushIOManager sharedInstance] setLoggingEnabled:YES];
    if([logLevel  isEqualToString:@"info"])
        [[PushIOManager sharedInstance] setLogLevel:PIOLogLevelInfo]; //PIOLogLevelWarn or PIOLogLevelError
    if([logLevel  isEqualToString:@"verbose"])
        [[PushIOManager sharedInstance] setLogLevel:PIOLogLevelVerbose]; //PIOLogLevelWarn or PIOLogLevelError
    if([logLevel  isEqualToString:@"debug"])
        [[PushIOManager sharedInstance] setLogLevel:PIOLogLevelDebug]; //PIOLogLevelWarn or PIOLogLevelError
    if([logLevel  isEqualToString:@"error"])
        [[PushIOManager sharedInstance] setLogLevel:PIOLogLevelError]; //PIOLogLevelWarn or PIOLogLevelError
    if([logLevel  isEqualToString:@"warn"])
        [[PushIOManager sharedInstance] setLogLevel:PIOLogLevelWarn]; //PIOLogLevelWarn or PIOLogLevelError
    if([logLevel  isEqualToString:@"assert"])
        [[PushIOManager sharedInstance] setLogLevel:PIOLogLevelNone]; //PIOLogLevelWarn or PIOLogLevelError
#endif
}

@end
