namespace TakeoutSaaS.Shared.Abstractions.Results;

/// <summary>
/// 非泛型便捷封装。
/// </summary>
public static class ApiResponse
{
    /// <summary>
    /// 仅返回成功消息（无数据）。
    /// </summary>
    /// <param name="message">提示信息。</param>
    /// <returns>封装后的成功响应。</returns>
    public static ApiResponse<object> Success(string? message = "操作成功")
        => ApiResponse<object>.Ok(message: message);

    /// <summary>
    /// 成功且携带数据。
    /// </summary>
    /// <param name="data">业务数据。</param>
    /// <param name="message">提示信息。</param>
    /// <returns>封装后的成功响应。</returns>
    public static ApiResponse<object> Ok(object? data, string? message = "操作成功")
        => data is null ? ApiResponse<object>.Ok(message: message) : ApiResponse<object>.Ok(data, message);

    /// <summary>
    /// 错误返回。
    /// </summary>
    /// <param name="code">错误码。</param>
    /// <param name="message">错误提示。</param>
    /// <returns>封装后的失败响应。</returns>
    public static ApiResponse<object> Failure(int code, string message)
        => ApiResponse<object>.Error(code, message);

    /// <summary>
    /// 错误返回（附带详情）。
    /// </summary>
    /// <param name="code">错误码。</param>
    /// <param name="message">错误提示。</param>
    /// <param name="errors">错误详情。</param>
    /// <returns>封装后的失败响应。</returns>
    public static ApiResponse<object> Error(int code, string message, object? errors = null)
        => ApiResponse<object>.Error(code, message, errors);
}
