package com.capgemini.fridaybooster.kubernetes.fbapp.controller;

import java.net.Inet4Address;
import java.net.UnknownHostException;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.capgemini.fridaybooster.kubernetes.fbapp.model.HostNameInfo;

import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/")
public class TestController {

	private final HostNameInfo infos;

	public TestController(@Value("${message}") String message) throws UnknownHostException {
		var ip = Inet4Address.getLocalHost().getHostAddress();
		var hostName = Inet4Address.getLocalHost().getHostName();

		infos = new HostNameInfo(hostName, ip, message);
	}

	@GetMapping("/")
	public Mono<HostNameInfo> getInfo() {
		return Mono.just(infos);
	}
}
