"use strict";
/**
 * Debug and file logging utilities.
 *
 * This module now delegates to the structured logger in `src/lib/observability/`.
 * The public API (`debug()`, `logToFile()`, `enableDebugLogs()`) is preserved
 * for backward compatibility — existing call sites don't need to change.
 *
 * New code should use `createLogger()` from `../lib/observability` directly.
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLogFilePath = getLogFilePath;
exports.configureLogFile = configureLogFile;
exports.initLogFile = initLogFile;
exports.logToFile = logToFile;
exports.debug = debug;
exports.enableDebugLogs = enableDebugLogs;
const chalk_1 = __importDefault(require("chalk"));
const logging_1 = require("./logging");
const ui_1 = require("../ui");
const observability_1 = require("../lib/observability");
const legacyLog = (0, observability_1.createLogger)('legacy');
let debugEnabled = false;
function getLogFilePath() {
    return (0, observability_1.getLogFilePath)();
}
/**
 * Configure the log file path and enable/disable state.
 * Call before initLogFile() to override defaults.
 */
function configureLogFile(opts) {
    (0, observability_1.configureLogFile)(opts);
}
/**
 * Initialize the log file with a run header.
 * @deprecated The structured logger handles initialization via `initLogger()`.
 * Kept for backward compatibility — safe to call but may be a no-op
 * if `initLogger()` has already been called.
 */
function initLogFile() {
    // initLogger() in bin.ts now handles file init.
    // This is kept as a no-op for any remaining call sites.
}
/**
 * Log a message to the log file.
 * Always writes regardless of debug flag (when logging is enabled).
 * Fails silently to avoid masking errors in catch blocks.
 *
 * @deprecated Use `createLogger('my-module').debug()` or `.info()` instead.
 */
function logToFile(...args) {
    const msg = args.map((a) => (0, logging_1.prepareMessage)(a)).join(' ');
    // Route through the structured logger at debug level.
    // The logger writes to the file with structured JSON.
    legacyLog.debug(msg);
}
function debug(...args) {
    if (!debugEnabled) {
        return;
    }
    const msg = args.map((a) => (0, logging_1.prepareMessage)(a)).join(' ');
    (0, ui_1.getUI)().log.info(chalk_1.default.dim(msg));
}
function enableDebugLogs() {
    debugEnabled = true;
}
