// 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 System.Linq;

namespace Hiperscan.SGS.SerialInterface
{
    public static class SerialInterfaceConfigurations
    {
        public static readonly SerialInterfaceConfig[] DEFAULT_USB_CONFIGS =
        {
            new SerialInterfaceConfig(VendorId.FTDI,      ProductId.SGS1900_GROUP,     SerialInterfaceConfig.BackendType.FT245BL, DeviceType.Sgs1900),
            new SerialInterfaceConfig(VendorId.HIPERSCAN, ProductId.APOIDENT2_SGS,    SerialInterfaceConfig.BackendType.FT245BL, DeviceType.ApoIdent),
            new SerialInterfaceConfig(VendorId.FTDI,      ProductId.SGS1900B,    SerialInterfaceConfig.BackendType.FT245BL, DeviceType.PTIM100),
            new SerialInterfaceConfig(VendorId.FTDI,      ProductId.SGS1900C,    SerialInterfaceConfig.BackendType.FT245BL, DeviceType.GerberScan),
            new SerialInterfaceConfig(VendorId.HIPERSCAN, ProductId.INNO_NIR,       SerialInterfaceConfig.BackendType.CP2130,  DeviceType.SgsNt),
            new SerialInterfaceConfig(VendorId.HIPERSCAN, ProductId.CALIBRATION_DEVICE,   SerialInterfaceConfig.BackendType.FT245BL, DeviceType.CalibrationDevice),
            new SerialInterfaceConfig(VendorId.HIPERSCAN, ProductId.ES20_OEM, SerialInterfaceConfig.BackendType.STM32, DeviceType.ApoIdent2X),
            new SerialInterfaceConfig(VendorId.HIPERSCAN, ProductId.APOIDENT_2X_ES20, SerialInterfaceConfig.BackendType.STM32, DeviceType.ApoIdent),
            new SerialInterfaceConfig(VendorId.HIPERSCAN, ProductId.FINDER2_USB_DEVICE, SerialInterfaceConfig.BackendType.Raspian, DeviceType.FinderX, true),
            new SerialInterfaceConfig(VendorId.HIPERSCAN, ProductId.ES22_SENSOR_FINDERX, SerialInterfaceConfig.BackendType.STM32, DeviceType.FinderX, false)
        };

        public static SerialInterfaceConfig GetUsbConfig(uint vendor_id, uint product_id, SerialInterfaceConfig.BackendType usb_backend)
        {
            return SerialInterfaceConfigurations.DEFAULT_USB_CONFIGS.SingleOrDefault(c => c.VendorId == vendor_id &&
                                                                  c.ProductId == product_id &&
                                                                  c.Backend == usb_backend) ?? throw new NotSupportedException("Unsupported USB device configuration.");
        }
    }
}
