package com.qaup.web.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.servers.Server;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import com.qaup.common.config.QaupConfig;

/**
 * SpringDoc OpenAPI 配置
 * 
 * @author qaup
 */
@Configuration
@Profile("dev")
public class OpenApiConfig {

    @Autowired
    private QaupConfig qaupConfig;

    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .info(apiInfo())
                .addSecurityItem(new SecurityRequirement().addList("Authorization"))
                .components(new io.swagger.v3.oas.models.Components()
                        .addSecuritySchemes("Authorization", new SecurityScheme()
                                .name("Authorization")
                                .type(SecurityScheme.Type.HTTP)
                                .scheme("bearer")
                                .bearerFormat("JWT")))
                .addServersItem(new Server().url("/").description("Default Server"));
    }

    private Info apiInfo() {
        return new Info()
                .title("后台管理系统接口文档")
                .description("用于后台管理系统，包括用户、角色、车辆信息等模块的接口说明。")
                .contact(new Contact()
                        .name(qaupConfig.getName())
                        .url(null)
                        .email(null))
                .version(qaupConfig.getVersion());
    }
} 