import Quickshell
import Quickshell.Io
import QtQuick

import qs.config
import qs.services

ShellRoot {
    IpcHandler {
        target: "weather-gpu-test"

        function gpuStatus(): string {
            return JSON.stringify({
                count: GraphicsDevices.devices.length,
                names: GraphicsDevices.devices.map(d => GraphicsDevices.shortName(d.name)),
                paths: GraphicsDevices.devices.map(d => d.path),
                selected: GraphicsDevices.selectedPath,
                resolved: GraphicsDevices.selected !== null,
                missing: GraphicsDevices.selectionMissing,
                error: GraphicsDevices.lastError
            });
        }

        function selectGpu(path: string): bool { return GraphicsDevices.select(path); }

        function geoSearch(query: string): void { Geocoding.search(query); }

        function geoStatus(): string {
            return JSON.stringify({
                searching: Geocoding.searching,
                count: Geocoding.results.length,
                top: Geocoding.results.length > 0 ? Geocoding.results[0].label : "",
                error: Geocoding.lastError
            });
        }

        function geoChooseTop(): bool {
            if (Geocoding.results.length === 0) return false;
            return Geocoding.choose(Geocoding.results[0]);
        }

        function storedLocation(): string {
            return JSON.stringify({
                label: DesktopPreferences.get("weatherLocation"),
                lat: DesktopPreferences.get("weatherLatitude"),
                lon: DesktopPreferences.get("weatherLongitude")
            });
        }
    }
}
