package com.hc.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @author 10696
 * 已将最新版本回退到最低版本
 */
@Configuration
public class Swagger3config {

    @Bean
    public Docket createRestApiFront() {
        return new Docket(DocumentationType.SWAGGER_12)
                .apiInfo(apiInfo())
                .groupName("front-api")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hc.web.controller.browser.front"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createRestApiBack() {
        return new Docket(DocumentationType.SWAGGER_12)
                .apiInfo(apiInfo())
                .groupName("back-api")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hc.web.controller.browser.back"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createRestApiApp() {
        return new Docket(DocumentationType.SWAGGER_12)
                .apiInfo(apiInfo())
                .groupName("app-api")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hc.web.controller.browser.app"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createRestApiCommon() {
        return new Docket(DocumentationType.SWAGGER_12)
                .apiInfo(apiInfo())
                .groupName("common-api")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hc.web.controller.browser.common"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createRestApiThird() {
        return new Docket(DocumentationType.SWAGGER_12)
                .apiInfo(apiInfo())
                .groupName("third-api")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hc.web.controller.browser.third"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Swagger一接口文档")
                .description("若请求体中出现主键字段，创建时间字段可主动去除")
                .contact(new Contact("作者", "作者地址", "作者邮箱"))
                .version("1.0")
                .build();
    }


}
