"use strict";
/**
 * Parse CLI thinking/effort override flags.
 *
 * Supported aliases:
 * - --thinking <value>
 * - --thinking=<value>
 * - --effort <value>
 * - --effort=<value>
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseThinkingOverride = void 0;
function parseThinkingValue(raw) {
    const trimmed = raw.trim();
    // Keep strict integer parsing for legacy compatibility with --thinking numeric budgets.
    if (/^-?\d+$/.test(trimmed)) {
        return Number.parseInt(trimmed, 10);
    }
    return trimmed;
}
/**
 * Parse first thinking/effort value from args.
 * If multiple flags are provided, first occurrence wins and later ones are reported as duplicates.
 */
function parseThinkingOverride(args) {
    let value;
    let sourceFlag;
    let sourceDisplay;
    const duplicateDisplays = [];
    for (let i = 0; i < args.length; i++) {
        const arg = args[i];
        let flag = null;
        let rawValue;
        let display = '';
        let form = 'separate';
        if (arg === '--thinking' || arg === '--effort') {
            flag = arg;
            const nextArg = args[i + 1];
            if (!nextArg || nextArg.startsWith('-')) {
                if (value === undefined) {
                    return { value, sourceFlag, sourceDisplay, duplicateDisplays, error: { flag, form } };
                }
                duplicateDisplays.push(`${flag} <missing-value>`);
                continue;
            }
            rawValue = nextArg;
            display = `${flag} ${rawValue}`;
            i += 1; // Consume value
        }
        else if (arg.startsWith('--thinking=') || arg.startsWith('--effort=')) {
            const [rawFlag, ...rest] = arg.split('=');
            const joined = rest.join('=');
            flag = rawFlag;
            rawValue = joined;
            form = 'inline';
            if (!rawValue || rawValue.trim() === '') {
                if (value === undefined) {
                    return { value, sourceFlag, sourceDisplay, duplicateDisplays, error: { flag, form } };
                }
                duplicateDisplays.push(`${flag}=<missing-value>`);
                continue;
            }
            display = `${flag}=${rawValue}`;
        }
        if (!flag || rawValue === undefined) {
            continue;
        }
        if (value === undefined) {
            value = parseThinkingValue(rawValue);
            sourceFlag = flag;
            sourceDisplay = display;
        }
        else {
            duplicateDisplays.push(display);
        }
    }
    return { value, sourceFlag, sourceDisplay, duplicateDisplays };
}
exports.parseThinkingOverride = parseThinkingOverride;
//# sourceMappingURL=thinking-arg-parser.js.map