package com.yfd.platform.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;

/**
 * swagger配置
 */
@Configuration
public class SwaggerConfig {

    Boolean swaggerEnabled = true;

    @Bean
    public Docket createRestGBApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .groupName("1. 系统管理")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yfd.platform.system.controller"))
                .paths(PathSelectors.any())
                .build()
                .pathMapping("/")
                .enable(swaggerEnabled);
    }

    @Bean
    public Docket createRestJobApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .groupName("2. 定时任务")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yfd.platform.modules.quartz.controller"))
                .paths(PathSelectors.any())
                .build()
                .pathMapping("/")
                .enable(swaggerEnabled);
    }


    @Bean
    public Docket createRestBaseDataApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .groupName("3. 基础数据管理")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yfd.platform.modules.basedata.controller"))
                .paths(PathSelectors.any())
                .build()
                .pathMapping("/")
                .enable(swaggerEnabled);
    }

    @Bean
    public Docket createPatrolTasksApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .groupName("4. 巡视任务管理")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yfd.platform.modules.patroltask.controller"))
                .paths(PathSelectors.any())
                .build()
                .pathMapping("/")
                .enable(swaggerEnabled);
    }

    @Bean
    public Docket createStationNodeApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .groupName("5. 机器人通讯")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yfd.platform.modules.robotapi.controller"))
                .paths(PathSelectors.any())
                .build()
                .pathMapping("/")
                .enable(swaggerEnabled);
    }

    @Bean
    public Docket createRobotComandApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .groupName("6. 机器人控制")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yfd.platform.modules.robotcomand.controller"))
                .paths(PathSelectors.any())
                .build()
                .pathMapping("/")
                .enable(swaggerEnabled);
    }

    @Bean
    public Docket createUavSystemApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .groupName("7. 无人机系统")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yfd.platform.modules.uavapi.controller"))
                .paths(PathSelectors.any())
                .build()
                .pathMapping("/")
                .enable(swaggerEnabled);
    }

    @Bean
    public Docket createAuxcontrolApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .groupName("8. 辅控接口")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yfd.platform.modules.auxcontrol.controller"))
                .paths(PathSelectors.any())
                .build()
                .pathMapping("/")
                .enable(swaggerEnabled);
    }
    @Bean
    public Docket createAlgorithmApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .groupName("9. 告警分类配置")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yfd.platform.modules.algorithm.controller"))
                .paths(PathSelectors.any())
                .build()
                .pathMapping("/")
                .enable(swaggerEnabled);
    }



    @Bean
    public Docket createTestApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .groupName("10. 测试接口")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yfd.platform.modules.test.controller"))
                .paths(PathSelectors.any())
                .build()
                .pathMapping("/")
                .enable(swaggerEnabled);
    }


    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("项目API 接口文档")
                .description("")
                .contact(new Contact("郑顺利", "郑顺利", "13910913995@163.com"))
                .version("3.0")
                .build();
    }
}
