using System.Net;

namespace Long.Core.Api;

/// <summary>
/// API 结果类
/// </summary>
public class ApiResult<T>
{
    /// <summary>
    /// 结果
    /// </summary>
    public T? Result { get; set; }

    /// <summary>
    /// 总记录数
    /// </summary>
    public int Total { get; set; }

    /// <summary>
    /// 成功标记
    /// </summary>
    public bool Success { get; set; }

    /// <summary>
    /// 消息
    /// </summary>
    public string Message { get; set; } = string.Empty;

    /// <summary>
    /// 堆栈跟踪
    /// </summary>
    public string StackTrace { get; set; } = string.Empty;

    /// <summary>
    /// 状态码
    /// </summary>
    public int StatusCode { get; set; }

    public ApiResult()
    {
        Success = true;
        StatusCode = (int)HttpStatusCode.OK;
    }

    public ApiResult(T data)
    {
        Result = data;
        Success = true;
        StatusCode = (int)HttpStatusCode.OK;
    }

    public ApiResult(bool success)
    {
        Success = success;
        StatusCode = (int)HttpStatusCode.OK;
    }

    public ApiResult(string message)
    {
        Success = false;
        Message = message;
        StatusCode = (int)HttpStatusCode.OK;
    }

    public ApiResult(T data, bool success)
    {
        Result = data;
        Success = success;
        StatusCode = (int)HttpStatusCode.OK;
    }

    public ApiResult(bool success, string message)
    {
        Success = success;
        Message = message;
        StatusCode = (int)HttpStatusCode.OK;
    }

    public ApiResult(T data, bool success, string message)
    {
        Result = data;
        Success = success;
        Message = message;
        StatusCode = (int)HttpStatusCode.OK;
    }

    public ApiResult(T data, bool success, string message, int statusCode)
    {
        Result = data;
        Success = success;
        Message = message;
        StatusCode = statusCode >= 0 ? statusCode : (int)HttpStatusCode.OK;
    }
}

/// <summary>
/// API 结果类
/// </summary>
public class ApiResult
{
    /// <summary>
    /// 成功标记
    /// </summary>
    public bool Success { get; set; }

    /// <summary>
    /// 消息
    /// </summary>
    public string Message { get; set; } = string.Empty;

    /// <summary>
    /// 堆栈跟踪
    /// </summary>
    public string StackTrace { get; set; } = string.Empty;

    /// <summary>
    /// 状态码
    /// </summary>
    public int StatusCode { get; set; }

    public string[] rows { get; set; } = Array.Empty<string>();

    public ApiResult()
    {
        Success = true;
        StatusCode = (int)HttpStatusCode.OK;
    }

    public ApiResult(bool success)
    {
        Success = success;
        StatusCode = (int)HttpStatusCode.OK;
    }

    public ApiResult(string message)
    {
        Success = false;
        Message = message;
        StatusCode = (int)HttpStatusCode.OK;
    }

    public ApiResult(bool success, string message)
    {
        Success = success;
        Message = message;
        StatusCode = (int)HttpStatusCode.OK;
    }

    public ApiResult(bool success, string message, int statusCode)
    {
        Success = success;
        Message = message;
        StatusCode = statusCode >= 0 ? statusCode : (int)HttpStatusCode.OK;
    }
}
