using System.Text;

namespace WmsMobileServe.Utils.HttpUtils.Entity;

public class ApiResponseInfo
{
    /// <summary>
    /// 请求 URL
    /// </summary>
    public string? RequestUrl { get; set; }

    /// <summary>
    /// 请求字符串
    /// </summary>
    public string? RequestMsg { get; set; }

    /// <summary>
    /// 响应字符串
    /// </summary>
    public string? ResponseMsg { get; set; }

    /// <summary>
    /// 请求时间
    /// </summary>
    public DateTime? RequestTime { get; set; }

    /// <summary>
    /// 响应时间
    /// </summary>
    public DateTime? ResponseTime { get; set; }

    /// <summary>
    /// 是否发送成功
    /// </summary>
    /// <remarks>
    /// 注意：这里仅表示服务端有响应
    /// </remarks>
    public bool IsSend { get; set; }

    /// <summary>
    /// 请求方式
    /// </summary>
    public string? RequestMethod { get; set; }

    /// <summary>
    /// 请求耗时
    /// </summary>
    public double UseTime { get; set; }

    /// <summary>
    /// 返回的异常，没有异常返回 null
    /// </summary>
    public Exception? Exception { get; set; }

    /// <summary>
    /// 重写toString
    /// </summary>
    /// <returns></returns>
    public override string ToString()
    {
        StringBuilder builder = new();
        builder.AppendLine($"[请求结果] {IsSend}");
        builder.AppendLine($"[请求方式] {RequestMethod}");
        builder.AppendLine($"[请求地址] {RequestUrl}");
        builder.AppendLine($"[请求信息] {RequestMsg}");
        builder.AppendLine($"[响应信息] {ResponseMsg}");
        builder.AppendLine($"[请求时间] {RequestTime}");
        builder.AppendLine($"[响应时间] {RequestTime}");
        builder.AppendLine($"[请求耗时] {UseTime} ms");
        if (Exception != default)
        {
            builder.AppendLine($"[异常信息] {Exception.Message}");
        }
        return builder.ToString();
    }
}

public class ApiResponseInfo<T> : ApiResponseInfo where T : class, new()
{
    /// <summary>
    /// 响应的实体类
    /// </summary>
    public T? ResponseEntity { get; set; }
}