"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildArchiveLogPath = exports.isPathInsideDirectory = exports.ensureLoggingDirectories = exports.getLegacyCliproxyLogsDir = exports.getLogArchiveDir = exports.getCurrentLogPath = exports.getNativeLogsDir = void 0;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const config_loader_facade_1 = require("../../config/config-loader-facade");
const LOGS_DIR = 'logs';
const ARCHIVE_DIR = 'archive';
const CURRENT_LOG_FILE = 'current.jsonl';
function getNativeLogsDir() {
    return path.join((0, config_loader_facade_1.getCcsDir)(), LOGS_DIR);
}
exports.getNativeLogsDir = getNativeLogsDir;
function getCurrentLogPath() {
    return path.join(getNativeLogsDir(), CURRENT_LOG_FILE);
}
exports.getCurrentLogPath = getCurrentLogPath;
function getLogArchiveDir() {
    return path.join(getNativeLogsDir(), ARCHIVE_DIR);
}
exports.getLogArchiveDir = getLogArchiveDir;
function getLegacyCliproxyLogsDir() {
    return path.join((0, config_loader_facade_1.getCcsDir)(), 'cliproxy', 'logs');
}
exports.getLegacyCliproxyLogsDir = getLegacyCliproxyLogsDir;
function ensureLoggingDirectories() {
    fs.mkdirSync(getNativeLogsDir(), { recursive: true, mode: 0o700 });
    fs.mkdirSync(getLogArchiveDir(), { recursive: true, mode: 0o700 });
}
exports.ensureLoggingDirectories = ensureLoggingDirectories;
function isPathInsideDirectory(candidatePath, rootDir) {
    const resolvedCandidate = path.resolve(candidatePath);
    const resolvedRoot = path.resolve(rootDir);
    const relative = path.relative(resolvedRoot, resolvedCandidate);
    return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));
}
exports.isPathInsideDirectory = isPathInsideDirectory;
function buildArchiveLogPath(timestamp = new Date()) {
    const compact = timestamp.toISOString().replace(/[:.]/g, '-');
    return path.join(getLogArchiveDir(), `ccs-${compact}.jsonl.gz`);
}
exports.buildArchiveLogPath = buildArchiveLogPath;
//# sourceMappingURL=log-paths.js.map