package com.njzscloud.common.core.http.interceptor;

import com.njzscloud.common.core.http.constant.HttpMethod;
import com.njzscloud.common.core.http.support.RequestInfo;
import com.njzscloud.common.core.http.support.ResponseInfo;
import com.njzscloud.common.core.jackson.Jackson;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Type;


/**
 * 组合式拦截器, 响应拦截器默认解析 JSON 类型参数
 *
 * @see RequestInterceptor
 * @see ResponseInterceptor
 */
@Slf4j
public class CompositeInterceptor implements RequestInterceptor, ResponseInterceptor {

    @Override
    public Object[] process(HttpMethod method, String url, Object[] args) {
        return null;
    }

    @Override
    public Object process(RequestInfo requestInfo, ResponseInfo responseInfo, Type responseType) {
        System.out.println(Jackson.toJsonStr(requestInfo));
        System.out.println(new String(requestInfo.body));

        Object data = new String(responseInfo.body);

        /* if (responseInfo.success) {
            if (responseInfo.body != null) {
                data = Jackson.toBean(responseInfo.body, responseType);
                log.info("Jackson: {}", JSON.toJSONString(data));
                data = JSON.parseObject(responseInfo.body, responseType);
                log.info("Fastjson: {}", JSON.toJSONString(data));
            }
        } else {
            log.error("HTTP请求失败");
        } */


        return data;
    }
}
