import { CallExpressionDriver } from '../../engine/code-writer/drivers/call-expression.driver.js';
import { ImportDriver } from '../../engine/code-writer/drivers/import.driver.js';
import { declareBackPackageModule, runGraphqlTypes } from '../package-helpers.js';
export default async function install(ctx) {
    await ctx.install([
        '@nestjs/passport',
        'passport',
        'passport-azure-ad',
        'passport-http-bearer',
    ]);
    declareBackPackageModule(ctx, 'MsEntraIdModule', '@app/modules/ms-entra-id/ms-entra-id.module');
    // Replace UseGuards arg with the two new guards
    const authDecorator = ctx.sourceFile('app', 'shared', 'decorators', 'auth.decorator.ts');
    ImportDriver.createImportItems(authDecorator, '@app/modules/ms-entra-id/shared/guards/azure-ad-bearer-auth.guard', ['AzureAdBearerAuthGuard']);
    ImportDriver.createImportItems(authDecorator, '@app/modules/ms-entra-id/shared/guards/authorization-permissions.guard', ['AuthorizationPermissionsGuard']);
    const callExpr = CallExpressionDriver.findCallExpression(authDecorator, 'UseGuards');
    if (callExpr) {
        CallExpressionDriver.removeAllArguments(callExpr);
        CallExpressionDriver.addArgument(callExpr, 'AzureAdBearerAuthGuard');
        CallExpressionDriver.addArgument(callExpr, 'AuthorizationPermissionsGuard');
    }
    authDecorator.saveSync();
    await runGraphqlTypes(ctx);
}
