import { INestApplication } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

export const setupSwagger = (app: INestApplication, configService: ConfigService): void => {
  if (!(configService.get<boolean>('swagger.enabled', { infer: true }) ?? false)) {
    return;
  }
  const config = new DocumentBuilder()
    .setTitle(configService.get<string>('swagger.title', 'Oudelaa API'))
    .setDescription(
      configService.get<string>('swagger.description', 'Social media backend API documentation'),
    )
    .setVersion(configService.get<string>('swagger.version', '1.0.0'))
    .addBearerAuth()
    .build();

  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup(configService.get<string>('swagger.path', 'docs'), app, document);
};
