using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace DG.Core
{
public class ApiResult : IApiResult
{
///
/// Represents an empty .
///
public static readonly IApiResult Empty = new ApiResult
{
Code = 0
};
///
/// Gets or sets the status code.
///
/// The status code.
[JsonPropertyName("code")]
public int Code { get; set; }
///
/// Gets or sets the message.
///
/// The message.
[JsonPropertyName("message")]
public string? Message { get; set; }
///
/// Creates a new instance of by the specified result.
///
/// The type of the result.
/// The result.
/// An instance inherited from interface.
public static IApiResult Succeed(TData data) => new ApiResult
{
Code = 0,
Data = data
};
///
/// Creates a new instance of by the specified error message.
///
/// The message.
/// The status code
/// An instance inherited from interface.
public static IApiResult Failed(string message, int? code = null) => new ApiResult
{
Code = code ?? -1,
Message = message
};
///
/// Creates a new instance of by the specified error message.
///
/// The type of the result.
/// The error result.
/// The message.
/// The status code.
/// An instance inherited from interface.
public static IApiResult Failed(TData data, string message, int? code = null) => new ApiResult
{
Code = code ?? -1,
Message = message,
Data = data
};
///
/// Creates a new instance of by the specified status code and message.
///
/// The status code.
/// The message.
/// An instance inherited from interface.
public static IApiResult From(int code, string message = null) => new ApiResult
{
Code = code,
Message = message
};
///
/// Creates a new instance of by the specified result.
///
/// The type of the result.
/// The result.
/// The status code.
/// The message.
/// An instance inherited from interface.
public static IApiResult From(TData data, int code, string message) => new ApiResult
{
Code = code,
Message = message,
Data = data
};
}
}