package com.friday.custody.service.trustService.cmsc.utils;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

@Slf4j
public class RestTemplateUtil {


    static RestTemplate restTemplate = new RestTemplate();

    public static HttpEntity<JSONObject> getDataFromRemote(String url, HttpHeaders headers) {
        return restTemplate
                .exchange(url,
                        HttpMethod.GET,
                        new HttpEntity<>(null, headers),
                        JSONObject.class);
    }

    public static HttpEntity<JSONObject> getDataFromRemote(String url, HttpHeaders headers , MultiValueMap<String, Object> bodyMap, HttpMethod httpMethod) {
        return restTemplate
                .exchange(url,
                        httpMethod,
                        new HttpEntity<>(bodyMap, headers),
                        JSONObject.class);
    }

}
