"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VALID_EVENT_TYPES = exports.MAX_EVENT_LIMIT = exports.DEFAULT_EVENT_LIMIT = void 0;
exports.parseWatchFlags = parseWatchFlags;
exports.parseWatchLimit = parseWatchLimit;
exports.parseWatchEventType = parseWatchEventType;
exports.isValidEventType = isValidEventType;
exports.DEFAULT_EVENT_LIMIT = 20;
exports.MAX_EVENT_LIMIT = 500;
exports.VALID_EVENT_TYPES = new Set([
    'file_save',
    'file_create',
    'file_delete',
    'file_rename',
    'git_commit',
    'package_change',
]);
function parseWatchFlags(rawArgs) {
    const positional = [];
    for (let i = 0; i < rawArgs.length; i++) {
        const a = String(rawArgs[i] || '');
        if (a === '--limit' && i + 1 < rawArgs.length) {
            i++;
            continue;
        }
        if (a.startsWith('--limit='))
            continue;
        if (a === '--type' && i + 1 < rawArgs.length) {
            i++;
            continue;
        }
        if (a.startsWith('--type='))
            continue;
        if (a.startsWith('--'))
            continue;
        positional.push(a);
    }
    return { positional };
}
function parseWatchLimit(rawArgs, fallback = exports.DEFAULT_EVENT_LIMIT) {
    for (let i = 0; i < rawArgs.length; i++) {
        const a = String(rawArgs[i] || '');
        if (a === '--limit' && i + 1 < rawArgs.length) {
            const n = parseInt(String(rawArgs[++i]), 10);
            if (Number.isFinite(n) && n > 0)
                return Math.min(n, exports.MAX_EVENT_LIMIT);
        }
        else if (a.startsWith('--limit=')) {
            const n = parseInt(a.slice('--limit='.length), 10);
            if (Number.isFinite(n) && n > 0)
                return Math.min(n, exports.MAX_EVENT_LIMIT);
        }
    }
    return fallback;
}
function parseWatchEventType(rawArgs) {
    for (let i = 0; i < rawArgs.length; i++) {
        const a = String(rawArgs[i] || '');
        if (a === '--type' && i + 1 < rawArgs.length) {
            return String(rawArgs[++i]);
        }
        if (a.startsWith('--type=')) {
            return a.slice('--type='.length);
        }
    }
    return undefined;
}
function isValidEventType(t) {
    return typeof t === 'string' && exports.VALID_EVENT_TYPES.has(t);
}
//# sourceMappingURL=watch-cli.js.map