package com.seer.teach.user.app.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.springdoc.core.models.GroupedOpenApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;


@Configuration
@Profile({"local","dev","test"})
public class UserApiConfig {

    @Value("${server.servlet.context-path:/}")
    private String contextPath;

    @Bean
    public OpenAPI userAppOpenAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("Seer Teach 用户端API")
                        .description("此文档详细说明了用户模块接口规范")
                        .version("v1.0.0")
                        .contact(new Contact()
                                .name("广东用嘉研发部")
                                .email("")))
                .components(new io.swagger.v3.oas.models.Components()
                        .addSecuritySchemes("token",
                                new SecurityScheme()
                                        .type(SecurityScheme.Type.APIKEY)
                                        .in(SecurityScheme.In.HEADER)
                                        .name("token")
                                        .description("输入sa-token令牌进行认证")))
                .addSecurityItem(new SecurityRequirement().addList("token"))
                .addServersItem(new Server().url(contextPath));
    }

    @Bean
    public GroupedOpenApi userAppApi() {
        return GroupedOpenApi.builder()
                .group("seer-user-app")
                .pathsToMatch("/app/**")
                .build();
    }

}