"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateEventType = validateEventType;
exports.validateImportance = validateImportance;
exports.validateProjectName = validateProjectName;
exports.validateSummary = validateSummary;
exports.validateMemoryEvent = validateMemoryEvent;
exports.sanitizeString = sanitizeString;
const VALID_EVENT_TYPES = [
    'file_event', 'edit', 'decision', 'error', 'fix',
    'verification', 'publish', 'handoff', 'pattern', 'style',
    'session', 'branch', 'risk', 'question', 'ai_work',
];
const VALID_CI_STATUSES = ['success', 'failure', 'cancelled', 'failed', 'rolled_back'];
const VALID_MEMORY_IMPORTANCE = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const VALID_SYNC_STRATEGIES = ['local-wins', 'remote-wins', 'importance', 'timestamp'];
function validateEventType(type) {
    if (!type)
        return 'Event type is required';
    if (!VALID_EVENT_TYPES.includes(type)) {
        return `Invalid event type: "${type}". Valid: ${VALID_EVENT_TYPES.join(', ')}`;
    }
    return null;
}
function validateImportance(importance) {
    if (importance == null)
        return null; // optional, defaults to 3
    if (typeof importance !== 'number' || !Number.isInteger(importance)) {
        return 'Importance must be an integer';
    }
    if (importance < 1 || importance > 10) {
        return 'Importance must be between 1 and 10';
    }
    return null;
}
function validateProjectName(name) {
    if (!name || typeof name !== 'string')
        return 'Project name is required';
    if (name.length > 200)
        return 'Project name must be 200 characters or less';
    if (/[<>:"/\\|?*\x00-\x1f]/.test(name))
        return 'Project name contains invalid characters';
    return null;
}
function validateSummary(summary) {
    if (!summary || typeof summary !== 'string')
        return 'Summary is required';
    if (summary.length > 2000)
        return 'Summary must be 2000 characters or less';
    return null;
}
function validateMemoryEvent(event) {
    const errors = [];
    const typeErr = validateEventType(event.type);
    if (typeErr)
        errors.push({ field: 'type', message: typeErr, value: event.type });
    const projErr = validateProjectName(event.project);
    if (projErr)
        errors.push({ field: 'project', message: projErr, value: event.project });
    const sumErr = validateSummary(event.summary);
    if (sumErr)
        errors.push({ field: 'summary', message: sumErr, value: event.summary });
    const impErr = validateImportance(event.importance);
    if (impErr)
        errors.push({ field: 'importance', message: impErr, value: event.importance });
    return errors;
}
function sanitizeString(input, maxLength = 2000) {
    if (typeof input !== 'string')
        return '';
    return input.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, '').trim().slice(0, maxLength);
}
//# sourceMappingURL=validation.js.map