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

import cn.hutool.core.map.MapUtil;

import java.util.List;
import java.util.Map;

public class ResponseInfo {
    public final boolean success;
    public final int code;
    public final String message;
    public final Map<String, List<String>> header;
    public final byte[] body;
    public final Exception e;

    public ResponseInfo(boolean success, int code, String message, Map<String, List<String>> header, byte[] body, Exception e) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.header = header;
        this.body = body;
        this.e = e;
    }

    public static ResponseInfo create(int code, String message, Map<String, List<String>> header, byte[] body) {
        return new ResponseInfo(code >= 200 && code <= 299, code, message, header, body, null);
    }

    public static ResponseInfo create(Exception e) {
        return new ResponseInfo(false, 0, e.getMessage(), MapUtil.empty(), new byte[0], e);
    }
}
