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

part of '../../desktop_notification_adapter_stub.dart';

/// Fallback backend that writes notification requests to stdout/logs.
final class StdoutNotificationBackend implements DesktopNotificationBackend {
  /// Creates a stdout fallback backend.
  StdoutNotificationBackend({
    required DesktopNotificationLogSink logSink,
    required this.platform,
  }) : _logSink = logSink;

  /// Private state stored as `_logSink` for this implementation.
  /// The field is intentionally scoped to this library so only the owning type can change the related scheduler or UI behavior.
  final DesktopNotificationLogSink _logSink;

  /// Platform this fallback represents.
  final DesktopNotificationPlatform platform;

  /// Returns the derived `isSupported` value for this object.
  /// Keeping this as an accessor gives callers a stable read surface while the owning type controls how the value is calculated.
  @override
  bool get isSupported => false;

  /// Runs the `deliver` operation and completes after its asynchronous work finishes.
  /// Callers should await the returned future so repository writes, UI refreshes, and failure handling happen in a predictable order.
  @override
  Future<void> deliver(NotificationRequest request) async {
    logger.warn(() => 'Stub desktop notification fallback delivery used. '
        'platform=${platform.name} notificationId=${request.id}');
    _logSink(
      'notification[$platform] ${request.id}: ${request.title} - '
      '${request.body}',
    );
  }

  /// Runs the `cancel` operation and completes after its asynchronous work finishes.
  /// Callers should await the returned future so repository writes, UI refreshes, and failure handling happen in a predictable order.
  @override
  Future<void> cancel(String id) async {
    final trimmed = id.trim();
    logger.finer(() => 'Stub desktop notification fallback cancel used. '
        'platform=${platform.name} notificationId=$trimmed');
    _logSink('notification[$platform] cancel: $trimmed');
  }
}
