import Quickshell
import Quickshell.Io
import QtQuick

import qs.services

ShellRoot {
    IpcHandler {
        target: "connectivity-test"

        function status(): string {
            return JSON.stringify({
                wifiDevice: Connectivity.wifiDevice ? Connectivity.wifiDevice.name : "",
                wiredDevice: Connectivity.wiredDevice ? Connectivity.wiredDevice.name : "",
                wiredConnected: !!(Connectivity.wiredDevice && Connectivity.wiredDevice.connected),
                networks: Connectivity.networks.length,
                activeSsid: Connectivity.activeNetwork ? Connectivity.activeNetwork.name : "",
                activeStrength: Connectivity.activeNetwork ? Connectivity.activeNetwork.signalStrength : -1,
                activeLabel: Connectivity.activeNetwork ? Connectivity.signalLabel(Connectivity.activeNetwork.signalStrength) : "",
                adapter: Connectivity.adapter ? true : false,
                btDevices: Connectivity.bluetoothDevices.length
            });
        }

        function labelFor(strength: real): string { return Connectivity.signalLabel(strength); }
        function setActive(on: bool): void { Connectivity.active = on; }
    }
}
