// lib/editor/input/diagnostic_logger.dart
//
// Compatibility facade over [BadNoteLog] + [PenEventRing]. The PDF editor's
// toolbar toggle still calls start/stop; globally, [BadNoteLog.start] runs at
// app launch so packaged builds always have a session file.

import 'dart:async';

import '../../diagnostics/badnote_log.dart';

class DiagnosticLogger {
  DiagnosticLogger._();
  static final DiagnosticLogger instance = DiagnosticLogger._();

  bool _verbose = false;
  bool get isActive => _verbose || BadNoteLog.instance.path != null;

  /// Absolute path of the structured session log (preferred), else null.
  String? get path => BadNoteLog.instance.path;

  /// Begin a verbose input session (also ensures the global log is running).
  Future<void> start() async {
    _verbose = true;
    await BadNoteLog.instance.start();
    BadNoteLog.instance.info(LogSubsystem.diag, 'verbose_input_on');
  }

  void log(String line) {
    BadNoteLog.instance.debug(LogSubsystem.penNative, line);
  }

  Future<void> stop() async {
    if (!_verbose) return;
    _verbose = false;
    BadNoteLog.instance.info(LogSubsystem.diag, 'verbose_input_off');
    await BadNoteLog.instance.flush();
  }
}
