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

export function setupSwagger(app: INestApplication) {
  const config = new DocumentBuilder()
    .setTitle('Insuniverse - OpenAPI 3.0')
    .setDescription('The Insuniverse API specification')
    .setVersion('2024-09-30')
    .addBearerAuth({ type: 'apiKey', in: 'header', name: 'Authorization' })
    .build();

  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('swagger', app, document);
}

//* 명시 스위치(SWAGGER_ENABLED=true)일 때만 연다. NODE_ENV 는 노출 스위치가 아니다.
export function isSwaggerEnabled(
  env: NodeJS.ProcessEnv = process.env,
): boolean {
  return env.SWAGGER_ENABLED === 'true';
}
