#import "upon.h"
#import "UponAudioRecorder.h"

@implementation upon {
    UponAudioRecorder * _recorder;
}

- (void) jniTest:(CDVInvokedUrlCommand*)command {
    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"OK"];
    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
     NSLog(@"%@", command);
}



- (void) requestPermision:(CDVInvokedUrlCommand*)command {
    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"OK"];
    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
    NSLog(@"%@", command);
}



- (void) startWavRecord:(CDVInvokedUrlCommand*)command {
    NSString * strFile = [command.arguments objectAtIndex:0];
    if (_recorder != nil) {
        _recorder = nil;
    }

    _recorder = [[UponAudioRecorder alloc] init];
    if ([_recorder startAudioRecorderWithFileUrl:strFile withSample:16000]) {
        CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"OK"];
        [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];

    } else {
        _recorder = nil;
         CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Failed"];
         [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];

    }
}



- (void) stopWavRecord:(CDVInvokedUrlCommand*)command {
    if (_recorder != nil) {
        [_recorder stopAudioRecorder];
    }

    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"OK"];
    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
    _recorder = nil;
}


- (void) mp3ToWav:(CDVInvokedUrlCommand*)command {
    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"not implemented"];
    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}



- (void) amrToWav:(CDVInvokedUrlCommand*)command {
    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"not implemented"];
    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}


- (void) getHotSpotInfo:(CDVInvokedUrlCommand*)command {
    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"not implemented"];
    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}



@end
