const BUDGET_COMMAND_PREFIX = '/budget';
export const BUDGET_USAGE_TEXT = 'Usage: /budget <token-budget> <task...> (examples: 500k, 1m, 250000)';
export function parseBudgetAmount(input) {
    const trimmed = input.trim();
    const match = /^(\d+(?:\.\d+)?)([kKmM]?)$/.exec(trimmed);
    if (!match)
        return null;
    const base = Number(match[1]);
    if (!Number.isFinite(base) || base <= 0)
        return null;
    const suffix = match[2].toLowerCase();
    const multiplier = suffix === 'm' ? 1_000_000 : suffix === 'k' ? 1_000 : 1;
    const value = Math.floor(base * multiplier);
    return value > 0 ? value : null;
}
export function parseBudgetCommand(input) {
    const trimmed = input.trim();
    if (!trimmed.startsWith(BUDGET_COMMAND_PREFIX))
        return null;
    const rest = trimmed.slice(BUDGET_COMMAND_PREFIX.length).trim();
    if (rest.length === 0) {
        throw new Error(BUDGET_USAGE_TEXT);
    }
    const firstSpace = rest.indexOf(' ');
    const amountText = firstSpace === -1 ? rest : rest.slice(0, firstSpace);
    const task = firstSpace === -1 ? '' : rest.slice(firstSpace + 1).trim();
    const budgetTokens = parseBudgetAmount(amountText);
    if (budgetTokens == null) {
        throw new Error('Invalid budget amount. Use values like 500k, 1m, or 250000.');
    }
    if (!task) {
        throw new Error(BUDGET_USAGE_TEXT);
    }
    return { budgetTokens, task };
}
//# sourceMappingURL=budget-command.js.map