using WinRT.BxlComponent.Plugin.BxlMpXamarinSDK.Abstractions;
using System;
using System.Linq;

namespace WinRT.BxlComponent.Plugin.BxlMpXamarinSDK
{
    /// <summary>
    /// Implementation for Feature
    /// </summary>
    internal class MPosDeviceFactoryImplementation : IMPosDeviceFactory
    {
        // 256 이상 값으로, 객체마다 유일한 장치 ID 값을 할당하고, openService 할 때, 실제 장치 ID 값을 할당
        private static int _uniqueDeviceId = 256;
        public MPosControllerDevices createDevice(MPosDeviceType deviceType)
        {
            MPosControllerDevices device = null;

            MPosDebug.WriteLine("createDevice : START");
            MPosDebug.WriteLine("createDevice : deviceType = " + deviceType.ToString());

            bool isMember = Enum.GetValues(typeof(MPosDeviceType)).Cast<int>().Any(x => x == (int)deviceType);

            if (isMember != true)
            {
                MPosDebug.WriteLine("createDevice : END");
                return null;
            }

            switch (deviceType)
            {
                case MPosDeviceType.MPOS_DEVICE_LABEL_PRINTER:
                    device = new MPosDeviceLabelPrinterImplementation((int)deviceType, _uniqueDeviceId++);
                    break;
                case MPosDeviceType.MPOS_DEVICE_PRINTER:
                    device = new MPosDevicePrinterImplementation((int)deviceType, _uniqueDeviceId++);
                    break;
                case MPosDeviceType.MPOS_DEVICE_CONFIG:         break;
                case MPosDeviceType.MPOS_DEVICE_HID:            break;
                case MPosDeviceType.MPOS_DEVICE_MSR:            break;
                case MPosDeviceType.MPOS_DEVICE_SCANNER:
                    device = new MPosControllerScannerImplementation((int)deviceType, _uniqueDeviceId++);
                    break;
                case MPosDeviceType.MPOS_DEVICE_RESERVED1:      break;
                case MPosDeviceType.MPOS_DEVICE_RFID:           break;
                case MPosDeviceType.MPOS_DEVICE_DALLAS_KEY:     break;
                case MPosDeviceType.MPOS_DEVICE_NFC:            break;
                case MPosDeviceType.MPOS_DEVICE_RESERVED2:      break;
                case MPosDeviceType.MPOS_DEVICE_UN_USBSERIAL:   break;
                case MPosDeviceType.MPOS_DEVICE_KNOWN:          break;
                case MPosDeviceType.MPOS_DEVICE_DISPLAY:        break;
                case MPosDeviceType.MPOS_DEVICE_USB_TO_SERIAL:
                    device = new MPosControllerTTYUSBImplementation((int)deviceType, _uniqueDeviceId++);
                    break;
                case MPosDeviceType.MPOS_DEVICE_SCALE:          break;
                case MPosDeviceType.MPOS_DEVICE_RESERVED3:      break;
                case MPosDeviceType.MPOS_DEVICE_CONFIG_LOOKUP:
                    device = new MposConfigurationImplementation((int)MPosDeviceType.MPOS_DEVICE_CONFIG, (int)MPosDeviceType.MPOS_DEVICE_CONFIG);
                    break;
            }

            MPosDebug.WriteLine("createDevice : END");
            return device;
        }
    }
}
