/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved. <a>http://www.crunii.com</a>
 */
package com.crunii.micro.gateway.router;

import com.crunii.micro.gateway.handler.RoutesDetailHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RequestPredicates.accept;

/**
 * @author 田平 create 2018年8月6日上午11:02:38
 */
@Component
@ConditionalOnProperty(name = "routes-detail.enabled", havingValue = "true")
public class RoutesDetailRouter {

	@Autowired
	private RoutesDetailHandler routesDetailHandler;

	@Value("${spring.application.name}")
	private String appName;

	@Bean(name = "routesDetailFunction")
	public RouterFunction<ServerResponse> callbackRouter() {
		return RouterFunctions.route(GET("/" + appName + "/RouteDetailRouter/routes")
				.and(accept(APPLICATION_JSON)), routesDetailHandler::routes);
	}

}