package cokr.xit.ens.modules.common.ctgy.intgrnbill.support.api;

import cokr.xit.ens.core.utils.CmmnUtil;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.PayApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Profile;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.nio.charset.Charset;
import java.util.Map;

/**
 * 페이결제 이용시스템 API
 *
 * @Description 결제에 필요한 정보를 이용시스템측에 요청 한다. 이용시스템측은 요청을 수신 할 수 있도록 API를 구축해야 한다.
 */
@Slf4j
@Component
//@Profile({"!local-test"})
public class PayUseSysApi implements PayApi {


    @Override
    public ResponseEntity<String> payUrl(String uri, Map<String, Object> mParam, HttpHeaders headers) {
       
        if (headers == null)
            headers = new HttpHeaders();
        headers.setContentType(new MediaType(MediaType.APPLICATION_JSON, Charset.forName("utf-8")));

       
        String param = CmmnUtil.toJsonString(mParam);

        return callApi(HttpMethod.POST, uri, param, headers);
    }

    @Override
    public ResponseEntity<String> payNotice(String uri, Map<String, Object> mParam, HttpHeaders headers) {
       
        if (headers == null)
            headers = new HttpHeaders();
        headers.setContentType(new MediaType(MediaType.APPLICATION_JSON, Charset.forName("utf-8")));

       
        String param = CmmnUtil.toJsonString(mParam);

        return callApi(HttpMethod.POST, uri, param, headers);
    }

    @Override
    public ResponseEntity<String> payAble(String uri, Map<String, Object> mParam, HttpHeaders headers) {
       
        if (headers == null)
            headers = new HttpHeaders();
        headers.setContentType(new MediaType(MediaType.APPLICATION_JSON, Charset.forName("utf-8")));

       
        String param = CmmnUtil.toJsonString(mParam);

        return callApi(HttpMethod.POST, uri, param, headers);
    }

    @Override
    public ResponseEntity<String> payResult(String uri, Map<String, Object> mParam, HttpHeaders headers) {
       
        if (headers == null)
            headers = new HttpHeaders();
        headers.setContentType(new MediaType(MediaType.APPLICATION_JSON, Charset.forName("utf-8")));

       
        String param = CmmnUtil.toJsonString(mParam);

        return callApi(HttpMethod.POST, uri, param, headers);
    }

    @Override
    public ResponseEntity<String> payCancelResult(String uri, Map<String, Object> mParam, HttpHeaders headers) {
       
        if (headers == null)
            headers = new HttpHeaders();
        headers.setContentType(new MediaType(MediaType.APPLICATION_JSON, Charset.forName("utf-8")));

       
        String param = CmmnUtil.toJsonString(mParam);

        return callApi(HttpMethod.POST, uri, param, headers);
    }
}
