// Created with MonoDevelop
//
//    Copyright (C) 2023 Hiperscan GmbH Dresden, Germany
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.


using System;
using Hiperscan.SGS.SerialInterface.USB;
using Hiperscan.Unix;

namespace Hiperscan.SGS.SerialInterface
{
    public static class SerialInterfaceInitializer
    {
        public static ISerialInterface Get(DeviceInfo device_info)
        {
            ISerialInterface serial_interface = null;

            switch (device_info.ProductId)
            {
                case ProductId.SGS1900_GROUP:
                case ProductId.SGS1900B:
                case ProductId.SGS1900C:
                case ProductId.APOIDENT2_SGS:
                case ProductId.CALIBRATION_DEVICE:
                    serial_interface = new FT245BL(device_info.VendorId, device_info.ProductId);
                    break;

                case ProductId.INNO_NIR:
                    serial_interface = new CP2130(device_info.VendorId, device_info.ProductId);
                    break;

                case ProductId.ES20_OEM:
                case ProductId.APOIDENT_2X_ES20:
                case ProductId.ES22_SENSOR_FINDERX:
                case ProductId.ES22_SENSOR_FINDER2:
                    serial_interface = new STM32(device_info.VendorId, device_info.ProductId);
                    break;

                case ProductId.FINDER2_USB_DEVICE:
                    serial_interface = new RaspianCom(device_info);
                    break;

                default:
                    string message = String.Format(Catalog.GetString("There is no serial interface available for product id {0}."), device_info.ProductId);
                    throw new Exception(message);
            }

            return serial_interface;
        }
    }
}
