package com.example.demo;

import com.example.demo.controller.RepositoryController;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.client.RestTemplate;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Tag;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.function.Predicate;

@SpringBootApplication
@EnableSwagger2
@ComponentScan(basePackageClasses = {
	RepositoryController.class
})
public class DemoApplication {
	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

    @Bean
    public Docket githubApi() {
        return new Docket(DocumentationType.SWAGGER_2)
            .groupName("repository-api")
            .apiInfo(apiInfo())
            .select()
            .paths(PathSelectors.regex("/repositories.*"))
            .build()
            .tags(new Tag("Repository Service", "All apis relating to repository"));
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
            .title("Git Java Backend repository API")
            .description("A simple REST service which will return details of all publicly available user repositories.")
            .license("Apache License Version 2.0")
            .licenseUrl("https://github.com/SamilCan/example/blob/master/LICENSE")
            .version("2.0")
            .build();
    }

    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder) {
        return builder.build();
    }

}
