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

"""GTK/GIO-based notification service for Linux."""

import logging

from gi.repository import Gio, Gtk

from ..notification_base import NotificationService

log = logging.getLogger(__name__)


class GioNotificationService(NotificationService):
    """Notification service using Gio.Notification (GTK standard on Linux)."""

    def __init__(self, application: Gtk.Application):
        """Initialize notification service.

        Args:
            application: GTK application instance for sending notifications
        """
        self._app = application
        log.debug("GioNotificationService initialized")

    def send_notification(self, title: str, body: str, notification_id: str) -> None:
        """Send a desktop notification using Gio.Notification.

        Args:
            title: Notification title
            body: Notification body text
            notification_id: Unique identifier for this notification
        """
        try:
            notification = Gio.Notification.new(title)
            notification.set_body(body)
            self._app.send_notification(notification_id, notification)
            log.debug(f"Sent notification: {title}")
        except Exception as e:
            log.warning(f"Failed to send notification: {e}")

    def is_supported(self) -> bool:
        """Check if Gio notifications are supported.

        Returns:
            True - Gio.Notification is always available with GTK4
        """
        return True
