package ite.security.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;

import static org.springframework.security.oauth2.client.web.reactive.function.client.ServerOAuth2AuthorizedClientExchangeFilterFunction.clientRegistrationId;

@Service
public class ClientService {
    private static Logger LOG = LoggerFactory.getLogger(ClientService.class);

    @Autowired
    private final WebClient webClient;


    public ClientService(WebClient webClient) {
        this.webClient = webClient;
    }


    public void callHallo() {
        webClient.get()
                .uri("http://localhost:8090/api/hello")
                // TODO 4: Add app-client to bo be used during HTTP GET
                //         It authenticates to Auth Server and adds received access token into Authorization header
                .retrieve()
                .bodyToMono(String.class)
                .subscribe(LOG::info);
    }
}
