package cn.com.citycloud.rent;

import cn.com.citycloud.configuration.auth.HeaderParameterBuilder;
import cn.com.citycloud.entity.purchase.PurchaseAnuualBudgetDetail;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.AlternateTypeRules;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

@Configuration
@EnableSwagger2
@Profile("dev")
public class Swagger2 {

    @Bean
    public Docket createRestApi() {
        HeaderParameterBuilder builder = new HeaderParameterBuilder();
        Docket docket = new Docket(DocumentationType.SWAGGER_2).enableUrlTemplating(false).globalOperationParameters(builder.build())
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.com.citycloud"))
                .paths(PathSelectors.any())
                .build();
        docket.alternateTypeRules(AlternateTypeRules.newMapRule(Integer.class, List.class));
        docket.alternateTypeRules(AlternateTypeRules.newMapRule(List.class, PurchaseAnuualBudgetDetail.class));
        return docket;
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("租赁服务系统 RESTful APIs")
                .description("租赁服务系统 RESTful APIs")
                .termsOfServiceUrl("http://aiyangniu.cn").contact(new Contact("爱养牛项目组", "http://aiyangniu.cn", ""))
                .version("1.0")
                .build();
    }
}
