# Copyright 2026, Jiri Eischmann <jiri@eischmann.cz> and the meshy contributors
# SPDX-License-Identifier: GPL-3.0-or-later

"""Platform-agnostic location service."""

from meshy.platforms import is_linux, is_macos


class LocationService:
    """Platform-agnostic location service.

    Provides GPS location access across different platforms:
    - macOS: CoreLocation framework
    - Linux: GeoClue2 D-Bus service
    """

    @staticmethod
    def get_location(callback):
        """Request current GPS location.

        Args:
            callback: Function called with (latitude, longitude, error).
                      On success: (float, float, None)
                      On failure: (None, None, error_string)

        Example:
            def on_location(lat, lon, error):
                if error:
                    print(f"Error: {error}")
                else:
                    print(f"Location: {lat}, {lon}")

            LocationService.get_location(on_location)
        """
        if is_macos():
            from meshy.platforms.macos.location_corelocation import get_location_macos

            get_location_macos(callback)
        elif is_linux():
            from meshy.platforms.linux.location_geoclue import get_location_linux

            get_location_linux(callback)
        else:
            callback(None, None, "Location services not available on this platform")
