
#import <Foundation/Foundation.h>
#import "RNAmeliaComponent.h"
#import "IPSAKConfiguration+Security.h"

@implementation RNAmeliaComponent

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

RCT_EXPORT_MODULE()
RCT_EXPORT_METHOD(concatStr:(NSString *)string1
				  secondString:(NSString *)string2
				  resolver:(RCTPromiseResolveBlock)resolve
				  rejecter:(RCTPromiseRejectBlock)reject) {
	resolve([NSString stringWithFormat:@"%@ %@", string1, string2]);
}

RCT_EXPORT_METHOD(initAmelia) {
	//IPSAKConfiguration *configuration = [IPSAKConfiguration configurationWithURL:
									//	 [NSURL URLWithString:@"https://blr-amelia-demo1-v3.ipsoft.com/Amelia/api/"]];
//	IPSAKConfiguration *configuration = [IPSAKConfiguration configurationWithURL:
//										 [NSURL URLWithString:@"https://ameliav3-dev.ipsoft.com/Amelia/api/"]];
	IPSAKConfiguration *configuration = [IPSAKConfiguration configurationWithURL:
										[NSURL URLWithString:@"https://blr-amelia-demo1-v3.ipsoft.com/Amelia/api/"]];
	configuration.domainSelectionMode = IPSAKDomainSelectionModeManual;
	configuration.allowAllHosts = TRUE;
	configuration.speechParams.enabled = false;
	self.chat = [IPSAKChat chatWithConfiguration:configuration];
	self.chat.sessionDelegate = self;
	[self.chat initialize];
}

-(void)chatInitialized:(IPSAKChat*)chat withAppConfig:(IPSAKAppConfig *)appConfig {
	[self.chat stepUp];

}

- (void)chat:(IPSAKChat *)chat didReceiveMessage:(IPSAKMessage *)message {
	// This is the quick way to get something showing. In a real application it is important
	//to check the messageType of the message.
	if (message.messageText != nil) {
		/*NSString *messageText = [NSString stringWithFormat:@"%@: %@
								 ",
								 message.fromUserDisplayName, message.messageText];
		[self.textView insertText:messageText];*/
	}
}

- (void)chat:(IPSAKChat *)chat inputEnabled:(BOOL)enabled {
	// It is now allowed to send new questions to Amelia until she is ready.
}

- (void)chat:(IPSAKChat *)chat error:(NSError *)error {
	NSLog(@"%s: %@", __PRETTY_FUNCTION__, error.localizedDescription);
}

- (void)chat:(IPSAKChat *)chat loginRequiredWithAuthSystems:(NSArray<IPSAKAuthSystem *> *)authSystems {
	//IPSAKLoginOptions *options = [[IPSAKLoginOptions alloc] initWithUsername:[NSString stringWithFormat:@"%@", @"sanjayk"] password:[NSString stringWithFormat:@"%@", @"Xonu@631268"]];
	
	IPSAKLoginOptions *options = [[IPSAKLoginOptions alloc] initWithAuthSystem:authSystems[0] username:@"navaneeth.nenmini@ipsoft.com" password:@"L3tm31n2!"];
	[self.chat login:options];
}

- (void)chat:(IPSAKChat *)chat domainSelectionRequired:(NSArray<IPSAKDomain *> *)domains {
	NSLog(@"%@", domains);
	[self.chat selectDomain:domains.firstObject];
}


@end
  
