/*
 * ********************************************************************************************************************
 *
 *                      :*$@@%$*:                         ;:                ;;    ;;
 *                    :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
 *                   :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
 *                   =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
 *                   =@*                                  %!              @ $= % %@=   =%@!      %=
 *              *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
 *            %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
 *          ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
 *          $@*   ;@@@%=!:                *@*
 *          =@$    ;;;!=%@@@@=!           =@!
 *           %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2019.  北京上格云技术有限公司
 *            ;%@@$=$@@%*       *@@@$=%@@%;
 *               ::;::             ::;::                                              All rights reserved.
 *
 * ********************************************************************************************************************
 */

package cn.sagacloud.server.algorithm

import org.slf4j.LoggerFactory
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Bean
import springfox.documentation.builders.ApiInfoBuilder
import springfox.documentation.builders.ParameterBuilder
import springfox.documentation.builders.PathSelectors
import springfox.documentation.builders.RequestHandlerSelectors
import springfox.documentation.schema.ModelRef
import springfox.documentation.service.ApiInfo
import springfox.documentation.service.Contact
import springfox.documentation.service.Parameter
import springfox.documentation.spi.DocumentationType
import springfox.documentation.spring.web.plugins.Docket
import springfox.documentation.swagger2.annotations.EnableSwagger2

/**
 * RESTful API文档生成器Swagger2配置
 *
 * @author  PLX
 */
@Configuration
@EnableSwagger2
open class Swagger2Config {
    companion object {
        // 日志
        private val logger = LoggerFactory.getLogger(Swagger2Config::class.java)
    } // Companion object

    /**
     * 创建RestApi文档生成器
     *
     * @return  返回文档生成器对象
     */
    @Bean
    open fun createRestApi(): Docket {
        val builder = ParameterBuilder()
        val pars = ArrayList<Parameter>()
        builder.name("ProjectId").description("项目ID").modelRef(ModelRef("string")).parameterType("header").required(false).build()
        pars.add(builder.build())
        return Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.sagacloud.server.algorithm"))
                .paths(PathSelectors.any())
                .build()
                .globalOperationParameters(pars)
    } // Function createRestApi()

    /**
     * 返回API信息基本
     *
     * @return  返回Api基本信息
     */
    private fun apiInfo(): ApiInfo {
        return ApiInfoBuilder()
                .title("Revit模型算法 API")
                .description("")
                .termsOfServiceUrl("http://www.sagacloud.cn/")
                .contact(Contact("jxing", "", "xingjinghao@sagacloud.cn"))
                .version("2.0")
                .build()
    } // Function apiInfo()
} // Class Swagger2Config