package com.gxwebsoft.common.core.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
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 io.swagger.v3.oas.models.Components;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * OpenAPI 配置
 *
 * @author WebSoft
 * @since 2025-09-11
 */
@Configuration
public class OpenApiConfig {
    
    @Resource
    private ConfigProperties config;

    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title(config.getSwaggerTitle())
                        .description(config.getSwaggerDescription())
                        .version(config.getSwaggerVersion())
                        .contact(new Contact()
                                .name("科技小王子")
                                .url("https://websoft.top")
                                .email("170083662@qq.com")))
                .addSecurityItem(new SecurityRequirement().addList("Authorization"))
                .components(new Components()
                        .addSecuritySchemes("Authorization",
                                new SecurityScheme()
                                        .type(SecurityScheme.Type.HTTP)
                                        .scheme("bearer")
                                        .bearerFormat("JWT")
                                        .description("JWT 认证")));
    }
}
