package com.sunda.spmsweb.swagger;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
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.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @program: spms0422
 * @description: Swagger Config
 * @author: Wayne Wu
 * @create: 2020-04-23 14:08
 **/

@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfig {

//    @Bean
//    public Docket createRestApi() {
//        return new Docket(DocumentationType.SWAGGER_2)
//                .apiInfo(apiInfo())
//                .select()
//                .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
//                .paths(PathSelectors.any())
//                .build();
//    }

    @Bean
    public Docket createRestApiUser() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("1.用户管理")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.sunda.spmsweb.usercontroller"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createRestApiOrder() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("2.物料及商城管理")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.sunda.spmsweb.ordercontroller"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createRestApiOA() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("3.OA系统对接管理")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.sunda.spmsweb.oacontroller"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createRestApiWms() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("4.库内作业管理")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.sunda.spmsweb.wmscontroller"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createRestApiOversea() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("5.海外仓")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.sunda.spmsweb.overseacontroller"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createRestApiMQ() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("6.消息队列MQ")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.sunda.spmsweb.ibmmqcontroller"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createRestApiSysLog() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("7.系统日志")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.sunda.spmsweb.commoncontroller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("SPMS 后端接口说明文档")
                .description("后端配置api文档，仅供开发参考")
                .termsOfServiceUrl("http://localhost:8080/doc.html")
                .contact("wuminsz@cn.ibm.com")
                .version("API V1.0")
                .build();
    }

}
