package com.njzscloud.common.http.support;

import cn.hutool.core.map.MapUtil;
import com.njzscloud.common.core.tuple.Tuple2;
import com.njzscloud.common.http.constant.HttpMethod;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;

import java.util.Map;

@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class RequestInfo {
    public final String desc;
    public final HttpMethod method;
    public final String url;
    public final Map<String, String> headers;
    public final String contentType;
    public final byte[] body;

    public static RequestInfo create(String desc, HttpMethod method, String url, Map<String, String> headers, Tuple2<String, byte[]> body) {
        String contentType = null;
        byte[] bytes = null;
        if (body != null) {
            contentType = body.get_0();
            bytes = body.get_1();
        }
        return new RequestInfo(desc, method, url, MapUtil.unmodifiable(headers), contentType, bytes);
    }
}
