using Atomx.Common.Enums;
using Atomx.Utils.Models;

namespace Atomx.Common.Models
{
    public class ApiResult<T> : Result<T>
    {
        /// <summary> 
        /// 服务器UTC时间
        /// </summary>
        public DateTime ServerTime => DateTime.UtcNow;



        public ApiResult()
        {

        }

        public ApiResult(Result<T> result)
        {
            Data = result.Data;
            Message = result.Message;
            Code = result.Code;
            Success = result.Success;
        }

        public ApiResult(T? data, string message, ResultCode code, bool success)
        {
            Data = data;
            Message = message;
            Code = (int)code;
            Success = success;
        }

        public ApiResult<T> IsSuccess(T? data = default)
        {
            return new ApiResult<T>(data, string.Empty, ResultCode.Success, true);
        }

        public ApiResult<T> IsFail(string message, T? data = default)
        {
            return new ApiResult<T>(data, message, ResultCode.Fail, false);
        }

        public ApiResult<T> IsFail(string message)
        {
            return new ApiResult<T>(default, message, ResultCode.Fail, false);
        }
    }
}
