import { SyntaxKind } from 'ts-morph';
export const CallExpressionDriver = {
    addArgument(callExpression, text) {
        callExpression.addArgument(text);
    },
    /** Find a call expression by its expression text (e.g., 'UseGuards' or 'ScheduleModule.forRoot'). */
    findCallExpression(sourceFile, expressionText) {
        return sourceFile
            .getDescendantsOfKind(SyntaxKind.CallExpression)
            .find((ce) => ce.getExpression().getText() === expressionText);
    },
    /** Find a call expression inside an array literal (e.g., ScheduleModule.forRoot() in imports). */
    findCallExpressionInArray(array, expressionText) {
        return array
            .getElements()
            .find((el) => el.getKind() === SyntaxKind.CallExpression &&
            el.getExpression().getText() === expressionText);
    },
    findCallExpressions(sourceFile, expressionText) {
        return sourceFile
            .getDescendantsOfKind(SyntaxKind.CallExpression)
            .filter((ce) => ce.getExpression().getText() === expressionText);
    },
    removeAllArguments(callExpression) {
        const args = callExpression.getArguments();
        for (let i = args.length - 1; i >= 0; i--) {
            callExpression.removeArgument(i);
        }
    },
    replaceArgument(callExpression, index, newText) {
        const args = callExpression.getArguments();
        if (index < args.length) {
            args[index].replaceWithText(newText);
        }
    },
};
