package org.wcs.plugin.webHttpClient.model;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.LocalDateTime;

/**
 * HTTP 响应类
 */
@Getter
@Setter
@NoArgsConstructor
public class HttpResponse {

    public HttpResponse(boolean isError, String message, HttpRequest request) {
        this.baseDataError = isError;
        this.errText = message;
        this.request = request;
    }

    /**
     * 基础信息是否是否错误
     */
    private boolean baseDataError;

    /**
     * 错误信息
     */
    private String errText;

    /**
     * 是否成功
     */
    private boolean success;

    /**
     * 请求方法
     */
    private String method;

    /**
     * 请求地址 key
     */
    private String addressKey;

    /**
     * 请求地址
     */
    private String url;

    /**
     * 请求时间
     */
    private LocalDateTime requestTime;

    /**
     * 响应时间
     */
    private LocalDateTime responseTime;

    /**
     * 请求耗时
     */
    private long useTime;

    /**
     * 响应码
     */
    private int responseCode;

    /**
     * 请求内容
     */
    private String requestText;

    /**
     * 响应内容
     */
    private String responseText;

    /**
     * 异常
     */
    private Exception exception;

    /**
     * 请求对象
     */
    private HttpRequest request;


    @Override
    public String toString() {
        if(baseDataError) {
            return "基础数据错误：" + errText +
                    "\n请求对象：" + request;
        }
        return "请求方法：" + method +
                "\n请求地址 key：" + addressKey +
                "\n请求地址：" + url +
                "\n请求时间：" + requestTime +
                "\n响应时间：" + responseTime +
                "\n请求耗时：" + useTime +
                "\n响应码：" + responseCode +
                "\n请求内容：" + requestText +
                "\n响应内容：" + responseText +
                "\n异常：" + exception;
    }



}
