package com.funcart.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import io.swagger.annotations.SwaggerDefinition;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@SwaggerDefinition(
        tags = {
                @io.swagger.annotations.Tag(name = "Email", description = "OpenEHR compositions.") })
public class Swagger{
        @Bean
        public Docket api() {
                return new Docket(DocumentationType.SWAGGER_2)
                                .select()
                                .apis(RequestHandlerSelectors.basePackage("com.funcart.controller"))
                                .paths(PathSelectors.any())
                                .build();
        }
        /*private ApiInfo apiInfo() {
                Contact contact = new Contac
                return   new ApiInfo( "mailserv",
                                "API to access emailserv",
                                "noomicroserv1.0",
                                "termsOfServiceUrl",
                                contact,
                                "license",
                                "www.funcart.com");
        }*/

        @Bean
        public WebMvcConfigurerAdapter corsConfigurer() {
                return new WebMvcConfigurerAdapter() {
                        @Override
                        public void addCorsMappings(CorsRegistry registry) {
                                registry.addMapping("/**");
                        }
                };
        }
}