#import "RNStarioPrinter.h"
#import "PrinterFunctions.h"

@implementation RNStarioPrinter

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

RCT_EXPORT_METHOD(check:(NSString *)portName
                  resolver:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject)
                    {
                      NSString* response = [PrinterFunctions CheckStatusWithPortname:portName portSettings:@"mini" sensorSetting:NoDrawer];
                      resolve(response);
                    }

RCT_EXPORT_METHOD(rawprint:(NSString *)printText
                  portName:(NSString *)portName
                  portSettings:(NSString *)portSettings
                  resolver:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject)
                    {
                        NSData *textNSData = [printText dataUsingEncoding:NSWindowsCP1252StringEncoding];
                        unsigned char *textData = (unsigned char *)malloc([textNSData length]);
                        [textNSData getBytes:textData];

                        [PrinterFunctions PrintTextWithPortname:portName portSettings:portSettings textData:textData textDataSize:(unsigned int)[textNSData length]];

                        resolve(@"success");
                    }
@end
