namespace HoneyBox.Admin.Models.Common;

/// <summary>
/// 通用 API 响应模型
/// </summary>
/// <typeparam name="T">数据类型</typeparam>
public class ApiResponse<T>
{
    /// <summary>
    /// 状态码 (0 表示成功)
    /// </summary>
    public int Code { get; set; }

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

    /// <summary>
    /// 数据
    /// </summary>
    public T? Data { get; set; }

    /// <summary>
    /// 创建成功响应
    /// </summary>
    public static ApiResponse<T> Success(T data, string message = "success")
        => new() { Code = 0, Message = message, Data = data };

    /// <summary>
    /// 创建错误响应
    /// </summary>
    public static ApiResponse<T> Error(int code, string message)
        => new() { Code = code, Message = message };
}

/// <summary>
/// 无数据的 API 响应
/// </summary>
public class ApiResponse : ApiResponse<object>
{
    /// <summary>
    /// 创建成功响应
    /// </summary>
    public static ApiResponse Success(string message = "success")
        => new() { Code = 0, Message = message };

    /// <summary>
    /// 创建错误响应
    /// </summary>
    public new static ApiResponse Error(int code, string message)
        => new() { Code = code, Message = message };
}
