//
//  RCTNuanceTextToSpeech.m
//  RCTNuanceTextToSpeech
//
//  Created by Dominique van Mil on 27/01/2017.
//  Copyright © 2017 SIMDO. All rights reserved.
//

#import "RCTNuanceTextToSpeech.h"
#import "RCTLog.h"
#import <React/RCTEventEmitter.h>

@implementation RCTNuanceTextToSpeech

- (NSArray<NSString *> *)supportedEvents {
    return @[@"didFinishPlaying"];
}

@synthesize nuanceTextToSpeechDelegate;

RCT_EXPORT_MODULE();

-(instancetype)init
{
  self = [super init];
  if (self) {
    nuanceTextToSpeechDelegate = [[NuanceTextToSpeechDelegate alloc] init];
    nuanceTextToSpeechDelegate.delegate = self;
  }

  return self;
}

-(void)didFinishPlaying {
    RCTLogInfo(@"RCTNuanceTextToSpeech #finishPlaying");
    [self sendEventWithName:@"didFinishPlaying" body:@{}];
}

RCT_EXPORT_METHOD(configure:(NSDictionary *)args)
{
  RCTLogInfo(@"RCTNuanceTextToSpeech #configure");
  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    [nuanceTextToSpeechDelegate configure:args];
  });
}

RCT_EXPORT_METHOD(speak:(NSDictionary *)args)
{
  RCTLogInfo(@"RCTNuanceTextToSpeech #speak");
  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    [nuanceTextToSpeechDelegate speak:args];
  });
}

RCT_EXPORT_METHOD(notify:(NSDictionary *)args)
{
  RCTLogInfo(@"RCTNuanceTextToSpeech #notify");
  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    [nuanceTextToSpeechDelegate notify:args];
  });
}

@end
