package com.seer.teach.admin.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;

/**
 * @Author: Captain
 * @Autograph: 安稳
 * @Description: SpringDoc OpenAPI配置类
 * @Date: 2022-11-03 02:01:09
 */
@Configuration
@Profile({"local","dev","test"})
public class AdminApiConfig {

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

    @Bean
    public OpenAPI adminOpenAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("Seer Teach 后台管理系统API")
                        .description("Seer Teach 后台管理系统API文档")
                        .version("v1.0.0")
                        .contact(new Contact()
                                .name("广东用嘉研发部")))
                .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 mallAdminApi() {
        return GroupedOpenApi.builder()
                .group("admin-mall")
                .pathsToMatch("/mall/**")
                .build();
    }

    @Bean
    public GroupedOpenApi mpAdminApi() {
        return GroupedOpenApi.builder()
                .group("admin-mp")
                .pathsToMatch("/mp/**")
                .build();
    }

    @Bean
    public GroupedOpenApi payAdminApi() {
        return GroupedOpenApi.builder()
                .group("admin-pay")
                .pathsToMatch("/pay/**")
                .build();
    }

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

    @Bean
    public GroupedOpenApi tvAdminApi() {
        return GroupedOpenApi.builder()
                .group("admin-tv")
                .pathsToMatch("/tv/**")
                .build();
    }

    @Bean
    public GroupedOpenApi teacherAdminApi() {
        return GroupedOpenApi.builder()
                .group("admin-teacher")
                .pathsToMatch("/teacher/**")
                .build();
    }

    @Bean
    public GroupedOpenApi commonAdminApi() {
        return GroupedOpenApi.builder()
                .group("admin-common")
                .pathsToMatch("/common/**")
                .build();
    }
}