"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProviderDriver = void 0;
const ts_morph_1 = require("ts-morph");
class ProviderDriver {
    static changeUseClass(object, provide, adapter) {
        if (!(object instanceof ts_morph_1.ObjectLiteralExpression))
            return;
        const properties = object.getProperties();
        for (const property of properties) {
            if (!(property instanceof ts_morph_1.PropertyAssignment))
                continue;
            if (ProviderDriver.isProvideWanted(object, provide) &&
                property.getName() === 'useClass') {
                property.setInitializer(adapter);
                break;
            }
        }
    }
    static isProvideWanted(object, provide) {
        var _a;
        if (!(object instanceof ts_morph_1.ObjectLiteralExpression))
            return false;
        const properties = object.getProperties();
        for (const property of properties) {
            if (!(property instanceof ts_morph_1.PropertyAssignment))
                continue;
            if (property.getName() === 'provide' &&
                ((_a = property.getInitializer()) === null || _a === void 0 ? void 0 : _a.getText()) === provide) {
                return true;
            }
        }
        return false;
    }
}
exports.ProviderDriver = ProviderDriver;
