using System;
using System.Collections.Generic;
using Microsoft.ReactNative.Managed;
using WinRT.BxlComponent.UwpWrapper;
using System.Runtime.InteropServices.WindowsRuntime;

namespace ReactNativeRnBixolonBgateLibs
{
    [ReactModule]
    public sealed class MPosControllerConfigProxy
    {
        private MposConfigImpl _printerDev;
        public MPosControllerConfigProxy()
        {
            _printerDev = new MposConfigImpl();
        }
        [ReactMethod("selectInterface")]
        public void selectInterface(string[] array, IReactPromise<int> promise)
        {
            promise.Resolve(_printerDev.selectInterface(
                Convert.ToInt32(array[0]),
                array[1])
                );
            return;
        }
        [ReactMethod("selectCommandMode")]
        public void selectCommandMode(int commandMode, IReactPromise<int> promise)
        {
            promise.Resolve(_printerDev.selectCommandMode(commandMode));
            return;
        }
        [ReactMethod("openService")]
        public async void openService(uint[] array, IReactPromise<int> promise)
        {
            promise.Resolve(await _printerDev.openService(
                array[0],
                array[1]
                ));
            return;
        }
        [ReactMethod("closeService")]
        public async void closeService(uint closeTimeout/*second*/, IReactPromise<int> promise)
        {
            promise.Resolve(await _printerDev.closeService(closeTimeout));
            return;
        }
        [ReactMethod("isOpen")]
        public void isOpen(IReactPromise<int> promise)
        {
            promise.Resolve(Convert.ToInt32(_printerDev.isOpen()));
            return;
        }
        [ReactMethod("getDeviceId")]
        public void getDeviceId(IReactPromise<int> promise)
        {
            promise.Resolve(Convert.ToInt32(_printerDev.getDeviceId()));
            return;
        }
        [ReactMethod("directIO")]
        public async void directIO([ReadOnlyArray()] byte[] data, IReactPromise<int> promise)
        {
            promise.Resolve(await _printerDev.directIO(data));
            return;
        }
        [ReactMethod("setTransaction")]
        public async void setTransaction(int transactionMode, IReactPromise<int> promise)
        {
            promise.Resolve(await _printerDev.setTransaction(transactionMode));
            return;
        }
        [ReactMethod("searchDevices")]
        public async void searchDevices(IReactPromise<IList<int>> promise)
        {
            promise.Resolve(await _printerDev.searchDevices());
            return;
        }
        [ReactMethod("getBgateSerialNumber")]
        public async void getBgateSerialNumber(IReactPromise<string> promise)
        {
            promise.Resolve(await _printerDev.getBgateSerialNumber());
            return;
        }
        [ReactMethod("getSerialConfig")]
        public async void getSerialConfig(int targetDeviceID, IReactPromise<IList<int>> promise)
        {
            promise.Resolve(await _printerDev.getSerialConfig(targetDeviceID));
            return;
        }
        [ReactMethod("getSerialConfiguration")]
        public async void getSerialConfiguration(int targetDeviceID, IReactPromise<IList<int>> promise)
        {
            promise.Resolve(await _printerDev.getSerialConfiguration(targetDeviceID));
            return;
        }
        [ReactMethod("setSerialConfig")]
        public async void setSerialConfig(int[] array, IReactPromise<int> promise) //int devID, int baudRate, int dataBit, int stopBit, int parityBit
        {
            promise.Resolve(await _printerDev.setSerialConfig(
                array[0],
                array[1],
                array[2],
                array[3],
                array[4]
                ));
            return;
        }
        [ReactMethod("setSerialConfiguration")]
        public async void setSerialConfiguration(int[] array, IReactPromise<int> promise) //int devID, int baudRate, int dataBit, int stopBit, int parityBit, int flowControl
        {
            promise.Resolve(await _printerDev.setSerialConfiguration(
                array[0],
                array[1],
                array[2],
                array[3],
                array[4],
                array[5]
                ));
            return;
        }
        [ReactMethod("getUSBDevice")]
        public async void getUSBDevice(int targetDeviceID, IReactPromise<string> promise)
        {
            promise.Resolve(await _printerDev.getUSBDevice(targetDeviceID));
            return;
        }
        [ReactMethod("getCustomDevices")]
        public async void getCustomDevices(int DeviceType, IReactPromise<string> promise)
        {
            promise.Resolve(await _printerDev.getCustomDevices(DeviceType));
            return;
        }
        [ReactMethod("addCustomDevice")]
        public async void addCustomDevice(int DeviceType, string vid, string pid, IReactPromise<string> promise)
        {
            promise.Resolve(await _printerDev.addCustomDevice(DeviceType, vid, pid));
            return;
        }
        [ReactMethod("deleteCustomDevice")]
        public async void deleteCustomDevice(int DeviceType, string vid, string pid, IReactPromise<string> promise)
        {
            promise.Resolve(await _printerDev.addCustomDevice(DeviceType, vid, pid));
            return;
        }
        [ReactMethod("reInitCustomDeviceType")]
        public async void reInitCustomDeviceType(int DeviceType, IReactPromise<string> promise)
        {
            promise.Resolve(await _printerDev.reInitCustomDeviceType(DeviceType));
            return;
        }
        
    }
}