// SPDX-FileCopyrightText: 2026 FocusFlow contributors
// SPDX-License-Identifier: AGPL-3.0-only

part of '../../../desktop_notification_adapter_io.dart';

/// Create the best default desktop notification backend.
DesktopNotificationBackend createDefaultDesktopNotificationBackend({
  DesktopNotificationPlatform? platform,
  DesktopProcessRunner? processRunner,
  DesktopNotificationLogSink? logSink,
}) {
  final resolvedPlatform = platform ?? _currentPlatform();
  final runner = processRunner ?? Process.run;
  final fallback = StdoutNotificationBackend(
    logSink: logSink ?? stdout.writeln,
    platform: resolvedPlatform,
  );
  logger.info(() => 'Resolved desktop notification backend. '
      'platform=${resolvedPlatform.name} hasCustomRunner=${processRunner != null} '
      'hasCustomLogSink=${logSink != null}');

  return switch (resolvedPlatform) {
    DesktopNotificationPlatform.linux => LinuxNotifySendBackend(
        processRunner: runner,
        fallback: fallback,
      ),
    DesktopNotificationPlatform.macos => MacOsNotificationBackend(
        processRunner: runner,
        fallback: fallback,
      ),
    DesktopNotificationPlatform.windows => fallback,
    DesktopNotificationPlatform.unsupported => fallback,
  };
}
