"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CallExpressionDriver = void 0;
const ts_morph_1 = require("ts-morph");
class CallExpressionDriver {
    static findCallExpression(sourceFile, functionName) {
        const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
        for (const callExpression of callExpressions) {
            if (callExpression.getExpression().getText() === functionName) {
                return callExpression;
            }
        }
    }
    static get(sourceFile, functionName) {
        const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
        const callExpressionsTarget = [];
        for (const callExpression of callExpressions) {
            if (callExpression.getExpression().getText() === functionName) {
                callExpressionsTarget.push(callExpression);
            }
        }
        return callExpressionsTarget;
    }
    static replaceArgument(callExpression, oldArgumentName, newArgumentName) {
        for (const [index, value] of callExpression.getArguments().entries()) {
            if (value.getText() === oldArgumentName) {
                callExpression.insertArgument(index, newArgumentName);
                CallExpressionDriver.removeArgument(callExpression, oldArgumentName);
                break;
            }
        }
    }
    static addArgument(callExpression, argumentName) {
        callExpression.addArgument(argumentName);
    }
    static removeArgument(callExpression, argumentName) {
        for (const [index, value] of callExpression.getArguments().entries()) {
            if (value.getText() === argumentName) {
                callExpression.removeArgument(index);
                break;
            }
        }
    }
    static removeAllArguments(callExpression) {
        // eslint-disable-next-line no-unreachable-loop
        for (const [index, value] of callExpression.getArguments().entries()) {
            callExpression.removeArgument(index);
            CallExpressionDriver.removeAllArguments(callExpression);
            break;
        }
    }
}
exports.CallExpressionDriver = CallExpressionDriver;
