/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package vip.xiaonuo.core.config;

import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMethod;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import vip.xiaonuo.common.pojo.CommonResult;

import javax.annotation.Resource;

/**
 * 业务相关配置
 *
 * @author xuyuxiang
 * @date 2022/7/7 16:18
 **/
@Configuration
public class BaseConfigure {

    @Resource
    private OpenApiExtensionResolver openApiExtensionResolver;

    /**
     * API文档分组配置
     *
     * @author xuyuxiang
     * @date 2022/7/7 16:18
     **/
    @Bean(value = "baseDocApi")
    public Docket baseDocApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("基础管理")
                        .description("基础管理")
                        .termsOfServiceUrl("https://www.xiaonuo.vip")
                        .contact(new Contact("HUIMV","https://www.xiaonuo.vip", "xuyuxiang29@foxmail.com"))
                        .version("2.0.0")
                        .build())
                .globalResponseMessage(RequestMethod.GET, CommonResult.responseList())
                .globalResponseMessage(RequestMethod.POST, CommonResult.responseList())
                .groupName("基础管理")
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .apis(RequestHandlerSelectors.basePackage("vip.xiaonuo.modular.base"))
                .paths(PathSelectors.any())
                .build().extensions(openApiExtensionResolver.buildExtensions("基础管理"));
    }

    @Bean(value = "aiDocApi")
    public Docket aiDocApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("AI巡检预警系统")
                        .description("AI巡检预警系统")
                        .termsOfServiceUrl("https://www.xiaonuo.vip")
                        .contact(new Contact("HUIMV","https://www.xiaonuo.vip", "xuyuxiang29@foxmail.com"))
                        .version("2.0.0")
                        .build())
                .globalResponseMessage(RequestMethod.GET, CommonResult.responseList())
                .globalResponseMessage(RequestMethod.POST, CommonResult.responseList())
                .groupName("AI巡检预警系统")
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .apis(RequestHandlerSelectors.basePackage("vip.xiaonuo.modular.ai"))
                .paths(PathSelectors.any())
                .build().extensions(openApiExtensionResolver.buildExtensions("AI巡检预警系统"));
    }

    @Bean(value = "biDocApi")
    public Docket biDocApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("BI驾驶舱系统")
                        .description("BI驾驶舱系统")
                        .termsOfServiceUrl("https://www.xiaonuo.vip")
                        .contact(new Contact("HUIMV","https://www.xiaonuo.vip", "xuyuxiang29@foxmail.com"))
                        .version("2.0.0")
                        .build())
                .globalResponseMessage(RequestMethod.GET, CommonResult.responseList())
                .globalResponseMessage(RequestMethod.POST, CommonResult.responseList())
                .groupName("BI驾驶舱系统")
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .apis(RequestHandlerSelectors.basePackage("vip.xiaonuo.modular.bi"))
                .paths(PathSelectors.any())
                .build().extensions(openApiExtensionResolver.buildExtensions("BI驾驶舱系统"));
    }

    @Bean(value = "energyDocApi")
    public Docket energyDocApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("智能能耗系统")
                        .description("智能能耗系统")
                        .termsOfServiceUrl("https://www.xiaonuo.vip")
                        .contact(new Contact("HUIMV","https://www.xiaonuo.vip", "xuyuxiang29@foxmail.com"))
                        .version("2.0.0")
                        .build())
                .globalResponseMessage(RequestMethod.GET, CommonResult.responseList())
                .globalResponseMessage(RequestMethod.POST, CommonResult.responseList())
                .groupName("智能能耗系统")
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .apis(RequestHandlerSelectors.basePackage("vip.xiaonuo.modular.energy"))
                .paths(PathSelectors.any())
                .build().extensions(openApiExtensionResolver.buildExtensions("智能能耗系统"));
    }

    @Bean(value = "envDocApi")
    public Docket envDocApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("智能环控系统")
                        .description("智能环控系统")
                        .termsOfServiceUrl("https://www.xiaonuo.vip")
                        .contact(new Contact("HUIMV","https://www.xiaonuo.vip", "xuyuxiang29@foxmail.com"))
                        .version("2.0.0")
                        .build())
                .globalResponseMessage(RequestMethod.GET, CommonResult.responseList())
                .globalResponseMessage(RequestMethod.POST, CommonResult.responseList())
                .groupName("智能环控系统")
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .apis(RequestHandlerSelectors.basePackage("vip.xiaonuo.modular.env"))
                .paths(PathSelectors.any())
                .build().extensions(openApiExtensionResolver.buildExtensions("智能环控系统"));
    }

    @Bean(value = "cleanDocApi")
    public Docket cleanDocApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("智能洗消系统")
                        .description("智能洗消系统")
                        .termsOfServiceUrl("https://www.xiaonuo.vip")
                        .contact(new Contact("HUIMV","https://www.xiaonuo.vip", "xuyuxiang29@foxmail.com"))
                        .version("2.0.0")
                        .build())
                .globalResponseMessage(RequestMethod.GET, CommonResult.responseList())
                .globalResponseMessage(RequestMethod.POST, CommonResult.responseList())
                .groupName("智能洗消系统")
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .apis(RequestHandlerSelectors.basePackage("vip.xiaonuo.modular.clean"))
                .paths(PathSelectors.any())
                .build().extensions(openApiExtensionResolver.buildExtensions("智能洗消系统"));
    }

    @Bean(value = "feedDocApi")
    public Docket feedDocApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("精准饲喂系统")
                        .description("精准饲喂系统")
                        .termsOfServiceUrl("https://www.xiaonuo.vip")
                        .contact(new Contact("HUIMV","https://www.xiaonuo.vip", "xuyuxiang29@foxmail.com"))
                        .version("2.0.0")
                        .build())
                .globalResponseMessage(RequestMethod.GET, CommonResult.responseList())
                .globalResponseMessage(RequestMethod.POST, CommonResult.responseList())
                .groupName("精准饲喂系统")
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .apis(RequestHandlerSelectors.basePackage("vip.xiaonuo.modular.feed"))
                .paths(PathSelectors.any())
                .build().extensions(openApiExtensionResolver.buildExtensions("精准饲喂系统"));
    }

    @Bean(value = "warningDocApi")
    public Docket warningDocApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("预警")
                        .description("预警")
                        .termsOfServiceUrl("https://www.xiaonuo.vip")
                        .contact(new Contact("HUIMV","https://www.xiaonuo.vip", "xuyuxiang29@foxmail.com"))
                        .version("2.0.0")
                        .build())
                .globalResponseMessage(RequestMethod.GET, CommonResult.responseList())
                .globalResponseMessage(RequestMethod.POST, CommonResult.responseList())
                .groupName("预警")
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .apis(RequestHandlerSelectors.basePackage("vip.xiaonuo.modular.warning"))
                .paths(PathSelectors.any())
                .build().extensions(openApiExtensionResolver.buildExtensions("预警"));
    }
}
