package org.xyzh.auth.config;

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

import java.util.List;

/**
 * OpenAPI 配置类 - Auth 服务
 * 配置 Swagger/OpenAPI 文档，方便 Apifox 导入接口和对象进行测试
 * 
 * @author yslg
 */
@Configuration
public class OpenApiConfig {

    @Bean
    public OpenAPI authOpenAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("认证服务 API 文档")
                        .description("""
                                认证服务接口文档，包括登录、登出、Token刷新等功能。
                                
                                ## 使用说明
                                1. 访问 Swagger UI: http://localhost:8081/urban-lifeline/auth/swagger-ui.html
                                2. 访问 OpenAPI JSON: http://localhost:8081/urban-lifeline/auth/v3/api-docs
                                3. 在 Apifox 中导入 OpenAPI JSON 进行接口测试
                                """)
                        .version("1.0.0")
                        .contact(new Contact()
                                .name("yslg")
                                .email("3401275564@qq.com"))
                        .license(new License()
                                .name("Apache 2.0")
                                .url("https://www.apache.org/licenses/LICENSE-2.0.html")))
                .servers(List.of(
                        new Server().url("http://localhost:8081/urban-lifeline/auth").description("本地开发环境")
                ))
                .addSecurityItem(new SecurityRequirement().addList("Bearer Authentication"))
                .components(new Components()
                        .addSecuritySchemes("Bearer Authentication",
                                new SecurityScheme()
                                        .type(SecurityScheme.Type.HTTP)
                                        .scheme("bearer")
                                        .bearerFormat("JWT")
                                        .description("请输入JWT Token，格式：Bearer {token}")));
    }
}

