namespace Tinkerforge
{
    public static class EMaster
    {
        public static (int Underrun, int CRCError, int NoACK, int Overflow) GetChibiErrorLog(this BrickMaster master)
        {
            master.GetChibiErrorLog(out int underrun, out int crcError, out int noAck, out int overflow);
            return (underrun, crcError, noAck, overflow);
        }

        public static (long Speed, char Parity, byte Stopbits) GetRS485Configuration(this BrickMaster master)
        {
            master.GetRS485Configuration(out long speed, out char parity, out byte stopbits);
            return (speed, parity, stopbits);
        }

        public static (string SSID, byte Connection, byte[] IP, byte[] SubnetMask, byte[] Gateway, int Port)
            GetWifiConfiguration(this BrickMaster master)
        {
            master.GetWifiConfiguration(out string ssid, out byte connection, out byte[] ip, out byte[] subnetMask,
                out byte[] gateway, out int port);
            return (ssid, connection, ip, subnetMask, gateway, port);
        }

        public static (byte Encryption, string Key, byte KeyIndex, byte EapOptions, int CaCertificateLength, int
            ClientCertificateLength, int PrivateKeyLength) GetWifiEncryption(this BrickMaster master)
        {
            master.GetWifiEncryption(out byte encryption, out string key, out byte keyIndex, out byte eapOptions,
                out int caCertificateLength, out int clientCertificateLength, out int privateKeyLength);
            return (encryption, key, keyIndex, eapOptions, caCertificateLength, clientCertificateLength,
                privateKeyLength);
        }

        public static (byte[] MacAddress, byte[] BSSID, byte Channel, short RSSI, byte[] IP, byte[] SubnetMask, byte[]
            Gateway, long RXCount, long TXCount, byte State) GetWifiStatus(this BrickMaster master)
        {
            master.GetWifiStatus(out byte[] macAddress, out byte[] bssid, out byte channel, out short rssi,
                out byte[] ip, out byte[] subnetMask, out byte[] gateway, out long rxCount, out long txCount,
                out byte state);
            return (macAddress, bssid, channel, rssi, ip, subnetMask, gateway, rxCount, txCount, state);
        }

        public static (int Index, byte[] Data, byte DataLength) GetWifiCertificate(this BrickMaster master, int index)
        {
            master.GetWifiCertificate(index, out byte[] data, out byte dataLength);
            return (index, data, dataLength);
        }

        public static (long Overflow, int LowWatermark, int Used) GetWifiBufferInfo(this BrickMaster master)
        {
            master.GetWifiBufferInfo(out long overflow, out int lowWatermark, out int used);
            return (overflow, lowWatermark, used);
        }

        public static (byte Connection, byte[] IP, byte[] SubnetMask, byte[] Gateway, int Port)
            GetEthernetConfiguration(this BrickMaster master)
        {
            master.GetEthernetConfiguration(out byte connection, out byte[] ip, out byte[] subnetMask,
                out byte[] gateway, out int port);
            return (connection, ip, subnetMask, gateway, port);
        }

        public static (byte[] MACAddress, byte[] IP, byte[] SubnetMask, byte[] Gateway, long RXCount, long TXCount,
            string Hostname) GetEthernetStatus(this BrickMaster master)
        {
            master.GetEthernetStatus(out byte[] macAddress, out byte[] ip, out byte[] subnetMask, out byte[] gateway,
                out long rxCount, out long txCount, out string hostname);
            return (macAddress, ip, subnetMask, gateway, rxCount, txCount, hostname);
        }

        public static (byte Sockets, int Port) GetEthernetWebsocketConfiguration(this BrickMaster master)
        {
            master.GetEthernetWebsocketConfiguration(out byte sockets, out int port);
            return (sockets, port);
        }

        public static (byte Length, byte[] Data, byte Result) ReadWifi2SerialPort(this BrickMaster master, byte length)
        {
            master.ReadWifi2SerialPort(length, out byte[] data, out byte result);
            return (length, data, result);
        }

        public static (int Port, int WebsocketPort, int WebsitePort, byte PhyMode, byte SleepMode, byte Website)
            GetWifi2Configuration(this BrickMaster master)
        {
            master.GetWifi2Configuration(out int port, out int websocketPort, out int websitePort, out byte phyMode,
                out byte sleepMode, out byte website);
            return (port, websocketPort, websitePort, phyMode, sleepMode, website);
        }

        public static (bool ClientEnabled, byte ClientStatus, byte[] ClientIP, byte[] ClientSubnetMask, byte[]
            ClientGateway, byte[] ClientMACAddress, long ClientRXCount, long ClientTXCount, short ClientRSSI, bool
            ApEnabled, byte[] ApIP, byte[] ApSubnetMask, byte[] ApGateway, byte[] ApMACAddress, long ApRXCount, long
            ApTXCount, byte ApConnectedCount) GetWifi2Status(this BrickMaster master)
        {
            master.GetWifi2Status(out bool clientEnabled, out byte clientStatus, out byte[] clientIP,
                out byte[] clientSubnetMask, out byte[] clientGateway, out byte[] clientMACAddress,
                out long clientRXCount, out long clientTXCount, out short clientRSSI, out bool apEnabled,
                out byte[] apIP, out byte[] apSubnetMask, out byte[] apGateway, out byte[] apMACAddress,
                out long apRXCount, out long apTXCount, out byte apConnectedCount);
            return (clientEnabled, clientStatus, clientIP, clientSubnetMask, clientGateway, clientMACAddress,
                clientRXCount, clientTXCount, clientRSSI, apEnabled, apIP, apSubnetMask, apGateway, apMACAddress,
                apRXCount, apTXCount, apConnectedCount);
        }

        public static (bool Enable, string SSID, byte[] IP, byte[] SubnetMask, byte[] Gateway, byte[] MacAddress, byte[]
            BSSID) GetWifi2ClientConfiguration(this BrickMaster master)
        {
            master.GetWifi2ClientConfiguration(out bool enable, out string ssid, out byte[] ip, out byte[] subnetMask,
                out byte[] gateway, out byte[] macAddress, out byte[] bssid);
            return (enable, ssid, ip, subnetMask, gateway, macAddress, bssid);
        }

        public static (bool Enable, string SSID, byte[] IP, byte[] SubnetMask, byte[] Gateway, byte Encryption, bool
            Hidden, byte Channel, byte[] MACAddress) GetWifi2APConfiguration(this BrickMaster brick)
        {
            brick.GetWifi2APConfiguration(out bool enable, out string ssid, out byte[] ip, out byte[] subnetMask,
                out byte[] gateway, out byte encryption, out bool hidden, out byte channel, out byte[] macAddress);
            return (enable, ssid, ip, subnetMask, gateway, encryption, hidden, channel, macAddress);
        }

        public static (bool Enable, byte[] RootIP, byte[] RootSubnetMask, byte[] RootGateway, byte[] RouterBSSID, byte[]
            GroupID, string GroupSSIDPrefix, byte[] GatewayIP, int GatewayPort) GetWifi2MeshConfiguration(
                this BrickMaster master)
        {
            master.GetWifi2MeshConfiguration(out bool enable, out byte[] rootIP, out byte[] rootSubnetMask,
                out byte[] rootGateway, out byte[] routerBSSID, out byte[] groupID, out string groupSSIDPrefix,
                out byte[] gatewayIP, out int gatewayPort);
            return (enable, rootIP, rootSubnetMask, rootGateway, routerBSSID, groupID, groupSSIDPrefix, gatewayIP,
                gatewayPort);
        }

        public static (byte Status, bool RootNode, bool RootCandidate, int ConnectedNodes, long RXCount, long TXCount)
            GetWifi2MeshCommonStatus(this BrickMaster master)
        {
            master.GetWifi2MeshCommonStatus(out byte status, out bool rootNode, out bool rootCandidate,
                out int connectedNodes, out long rxCount, out long txCount);
            return (status, rootNode, rootCandidate, connectedNodes, rxCount, txCount);

        }

        public static (string Hostname, byte[] IP, byte[] SubnetMask, byte[] Gateway, byte[] MACAddress)
            GetWifi2MeshClientStatus(this BrickMaster master)
        {
            master.GetWifi2MeshClientStatus(out string hostname, out byte[] ip, out byte[] subnetMask,
                out byte[] gateway, out byte[] macAddress);
            return (hostname, ip, subnetMask, gateway, macAddress);
        }

        public static (string SSID, byte[] IP, byte[] SubnetMask, byte[] Gateway, byte[] MACAddress)
            GetWifi2MeshAPStatus(this BrickMaster master)
        {
            master.GetWifi2MeshAPStatus(out string ssid, out byte[] ip, out byte[] subnetMask, out byte[] gateway,
                out byte[] macAddress);
            return (ssid, ip, subnetMask, gateway, macAddress);
        }

        public static (char Port, byte ProtocolVersion, byte[] FirmwareVersion, string Name) GetProtocol1BrickletName(
            this BrickMaster master, char port)
        {
            master.GetProtocol1BrickletName(port, out byte protocolVersion, out byte[] firmwareVersion, out string name);
            return (port, protocolVersion, firmwareVersion, name);
        }

        public static (char Option, int Min, int Max) GetStackCurrentCallbackThreshold(this BrickMaster master)
        {
            master.GetStackCurrentCallbackThreshold(out char option, out int min, out int max);
            return (option, min, max);
        }

        public static (char Option, int Min, int Max) GetStackVoltageCallbackThreshold(this BrickMaster master)
        {
            master.GetStackVoltageCallbackThreshold(out char option, out int min, out int max);
            return (option, min, max);
        }

        public static (char Option, int Min, int Max) GetUSBVoltageCallbackThreshold(this BrickMaster master)
        {
            master.GetUSBVoltageCallbackThreshold(out char option, out int min, out int max);
            return (option, min, max);
        }

    }
}
