/**
 * `olam upgrade --history` — read + format the JSONL audit log.
 *
 * Phase 2c — C2.
 */
import { readUpgradeLog, formatHistoryTable, formatHistoryJson, UPGRADE_LOG_PATH } from './upgrade-log.js';
import { printInfo } from '../output.js';
export function parseHistoryOpts(raw) {
    const rawLimit = raw.n;
    const limit = typeof rawLimit === 'number'
        ? rawLimit
        : typeof rawLimit === 'string'
            ? Number.parseInt(rawLimit, 10)
            : 10;
    return {
        limit: Number.isFinite(limit) && limit > 0 ? limit : 10,
        json: raw.json === true,
    };
}
export function handleHistory(opts) {
    const rows = readUpgradeLog(opts.limit);
    if (opts.json) {
        process.stdout.write(formatHistoryJson(rows) + '\n');
        return;
    }
    if (rows.length === 0) {
        printInfo('Log file', UPGRADE_LOG_PATH);
        process.stdout.write(formatHistoryTable(rows) + '\n');
        return;
    }
    printInfo('Log file', UPGRADE_LOG_PATH);
    process.stdout.write(formatHistoryTable(rows) + '\n');
}
//# sourceMappingURL=upgrade-history.js.map