export const DEFAULT_LEARNING_SETTINGS = {
    enabled: true,
    review: {
        mode: "auto",
    },
    memory: {
        enabled: true,
        reviewIntervalTurns: 5,
        reviewIntervalMinutes: 60,
    },
    skills: {
        enabled: true,
        autoSave: true,
        reviewToolIterations: 8,
        curatorEnabled: true,
        curator: {
            staleAfterDays: 30,
            archiveAfterDays: 90,
            autoArchive: true,
            backupBeforeRun: true,
            pruneAfterDays: 180,
            consolidateIntervalDays: 7,
        },
    },
};
function asObject(value) {
    return typeof value === "object" && value !== null && !Array.isArray(value)
        ? value
        : {};
}
function asBoolean(value, fallback) {
    return typeof value === "boolean" ? value : fallback;
}
function asPositiveInteger(value, fallback) {
    if (typeof value !== "number" || !Number.isFinite(value))
        return fallback;
    const normalized = Math.floor(value);
    return normalized > 0 ? normalized : fallback;
}
export function normalizeLearningSettings(input) {
    const root = asObject(input);
    const memory = asObject(root.memory);
    const review = asObject(root.review);
    const skills = asObject(root.skills);
    return {
        enabled: asBoolean(root.enabled, DEFAULT_LEARNING_SETTINGS.enabled),
        review: {
            mode: asReviewMode(review.mode, DEFAULT_LEARNING_SETTINGS.review.mode),
        },
        memory: {
            enabled: asBoolean(memory.enabled, DEFAULT_LEARNING_SETTINGS.memory.enabled),
            reviewIntervalTurns: asPositiveInteger(memory.reviewIntervalTurns, DEFAULT_LEARNING_SETTINGS.memory.reviewIntervalTurns),
            reviewIntervalMinutes: typeof memory.reviewIntervalMinutes === "number" &&
                Number.isFinite(memory.reviewIntervalMinutes) &&
                memory.reviewIntervalMinutes >= 0
                ? Math.floor(memory.reviewIntervalMinutes)
                : DEFAULT_LEARNING_SETTINGS.memory.reviewIntervalMinutes,
        },
        skills: {
            enabled: asBoolean(skills.enabled, DEFAULT_LEARNING_SETTINGS.skills.enabled),
            autoSave: asBoolean(skills.autoSave, DEFAULT_LEARNING_SETTINGS.skills.autoSave),
            reviewToolIterations: asPositiveInteger(skills.reviewToolIterations, DEFAULT_LEARNING_SETTINGS.skills.reviewToolIterations),
            curatorEnabled: asBoolean(skills.curatorEnabled, DEFAULT_LEARNING_SETTINGS.skills.curatorEnabled),
            curator: normalizeCuratorSettings(skills.curator),
        },
    };
}
function asReviewMode(value, fallback) {
    return value === "auto" || value === "suggest" || value === "off" ? value : fallback;
}
function normalizeCuratorSettings(input) {
    const curator = asObject(input);
    return {
        staleAfterDays: asPositiveInteger(curator.staleAfterDays, DEFAULT_LEARNING_SETTINGS.skills.curator.staleAfterDays),
        archiveAfterDays: asPositiveInteger(curator.archiveAfterDays, DEFAULT_LEARNING_SETTINGS.skills.curator.archiveAfterDays),
        autoArchive: asBoolean(curator.autoArchive, DEFAULT_LEARNING_SETTINGS.skills.curator.autoArchive),
        backupBeforeRun: asBoolean(curator.backupBeforeRun, DEFAULT_LEARNING_SETTINGS.skills.curator.backupBeforeRun),
        pruneAfterDays: asPositiveInteger(curator.pruneAfterDays, DEFAULT_LEARNING_SETTINGS.skills.curator.pruneAfterDays),
        consolidateIntervalDays: asPositiveInteger(curator.consolidateIntervalDays, DEFAULT_LEARNING_SETTINGS.skills.curator.consolidateIntervalDays),
    };
}
//# sourceMappingURL=learning-settings.js.map