package com.devjob.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * EP17: springdoc-openapi 의존성만 추가해도 /swagger-ui/index.html이 자동 생성된다.
 * 여기서는 문서 제목/설명과 JWT Bearer 인증 스킴(Authorize 버튼)을 추가로 설정한다.
 */
@Configuration
public class SwaggerConfig {

    @Bean
    public OpenAPI openAPI() {
        String bearerAuth = "bearerAuth";

        SecurityScheme securityScheme = new SecurityScheme()
                .type(SecurityScheme.Type.HTTP)
                .scheme("bearer")
                .bearerFormat("JWT")
                .in(SecurityScheme.In.HEADER)
                .name("Authorization");

        SecurityRequirement securityRequirement = new SecurityRequirement().addList(bearerAuth);

        return new OpenAPI()
                .info(new Info()
                        .title("DevJob API")
                        .description("채용 공고 플랫폼 API 문서")
                        .version("v1.0"))
                .addSecurityItem(securityRequirement)
                .components(new Components().addSecuritySchemes(bearerAuth, securityScheme));
    }
}
