"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateRetentionConfig = validateRetentionConfig;
const node_cron_1 = require("node-cron");
const type_js_1 = require("./type.js");
/**
 * Check if a path contains path traversal attempts
 */
function containsPathTraversal(filePath) {
    return filePath.includes("..");
}
/**
 * Validate and normalize retention configuration
 * @param config - Partial retention config
 * @returns Validated and complete retention config
 */
function validateRetentionConfig(config) {
    // Start with defaults
    const validated = {
        ...type_js_1.DEFAULT_RETENTION_CONFIG,
        ...config,
    };
    // Validate activeDays
    if (validated.activeDays < 1 || validated.activeDays > 365) {
        throw new Error("activeDays must be between 1 and 365");
    }
    // Validate archiveMaxFiles
    if (validated.archiveMaxFiles < 1 || validated.archiveMaxFiles > 100) {
        throw new Error("archiveMaxFiles must be between 1 and 100");
    }
    // Validate Cron expression
    if (!(0, node_cron_1.validate)(validated.archiveSchedule)) {
        throw new Error(`Invalid cron expression: ${validated.archiveSchedule}`);
    }
    // Validate archiveDir if provided
    if (validated.archiveDir && containsPathTraversal(validated.archiveDir)) {
        throw new Error(`Path traversal detected in archiveDir: ${validated.archiveDir}`);
    }
    return validated;
}
