"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DecoratorDriver = void 0;
const object_driver_1 = require("./object.driver");
const provider_driver_1 = require("./provider.driver");
class DecoratorDriver {
    static getClassDecoratorArguments(sourceFile, className, decorator) {
        const moduleClass = sourceFile.getClass(className);
        const moduleDecorator = moduleClass === null || moduleClass === void 0 ? void 0 : moduleClass.getDecorator(decorator);
        return moduleDecorator.getArguments()[0];
    }
    static addModuleDecoratorProperty(sourceFile, moduleName, decoratorName, propertyName, module) {
        if (DecoratorDriver.hasModuleDecoratorProperty(sourceFile, moduleName, decoratorName, propertyName, module))
            return;
        const classDecoratorArguments = DecoratorDriver.getClassDecoratorArguments(sourceFile, moduleName, decoratorName);
        const decoratorArrayProperty = object_driver_1.ObjectDriver.getInitializerProperty(classDecoratorArguments, propertyName);
        decoratorArrayProperty.addElement(module, { useNewLines: true });
    }
    static hasModuleDecoratorProperty(sourceFile, moduleName, decoratorName, propertyName, module) {
        const classDecoratorArguments = DecoratorDriver.getClassDecoratorArguments(sourceFile, moduleName, decoratorName);
        const decoratorArrayProperty = object_driver_1.ObjectDriver.getInitializerProperty(classDecoratorArguments, propertyName);
        for (const [index, value] of decoratorArrayProperty.getElements().entries()) {
            if (value.getText() === module)
                return true;
        }
        return false;
    }
    static changeModuleDecoratorPropertyAdapter(sourceFile, moduleName, decoratorName, propertyName, provide, adapter) {
        const classDecoratorArguments = DecoratorDriver.getClassDecoratorArguments(sourceFile, moduleName, decoratorName);
        const decoratorArrayProperty = object_driver_1.ObjectDriver.getInitializerProperty(classDecoratorArguments, propertyName);
        for (const [index, value] of decoratorArrayProperty.getElements().entries()) {
            provider_driver_1.ProviderDriver.changeUseClass(value, provide, adapter);
        }
    }
    static removeDecoratorAdapter(sourceFile, moduleName, decoratorName, propertyName, provide) {
        const classDecoratorArguments = DecoratorDriver.getClassDecoratorArguments(sourceFile, moduleName, decoratorName);
        const decoratorArrayProperty = object_driver_1.ObjectDriver.getInitializerProperty(classDecoratorArguments, propertyName);
        for (const [index, value] of decoratorArrayProperty.getElements().entries()) {
            if (provider_driver_1.ProviderDriver.isProvideWanted(value, provide)) {
                decoratorArrayProperty.removeElement(index);
            }
        }
    }
}
exports.DecoratorDriver = DecoratorDriver;
