using ApiResponseCode = BD.WTTS.Enums.ApiRspCode;

namespace BD.WTTS.Models.Abstractions;

/// <summary>
/// å¾®æœ�åŠ¡æ�¥å�£å“�åº”æ¨¡å�‹ç±»
/// </summary>
[GenerateTypeScript]
public abstract class ApiRspBase : IApiRsp
{
    ApiResponseCode mCode;
    bool mIsSuccess;

    [MPKey(0), MP2Key(0)]
#if __HAVE_N_JSON__
    [N_JsonProperty("ğŸ¦„")]
#endif
#if !__NOT_HAVE_S_JSON__
    [S_JsonProperty("ğŸ¦„")]
#endif
    public ApiResponseCode Code
    {
        get => mCode;
        set
        {
            mCode = value;
            // https://github.com/dotnet/corefx/blob/v3.1.6/src/System.Net.Http/src/System/Net/Http/HttpResponseMessage.cs#L143
            var code = (int)mCode;
            mIsSuccess = code >= 200 && code <= 299;
        }
    }

    [MPKey(LastMKeyIndex), MP2Key(LastMKeyIndex)]
#if __HAVE_N_JSON__
    [N_JsonProperty("ğŸ�´")]
#endif
#if !__NOT_HAVE_S_JSON__
    [S_JsonProperty("ğŸ�´")]
#endif
    public string? InternalMessage { get; set; }

    string? IApiRsp.InternalMessage
    {
        get => InternalMessage;
        set => InternalMessage = value;
    }

    /// <summary>
    /// æœ€å��ä¸€ä¸ª MessagePack åº�åˆ—åŒ– ä¸‹æ ‡ï¼Œç»§æ‰¿è‡ªæ­¤ç±»ï¼Œæ–°å¢�éœ€è¦�åº�åˆ—åŒ–çš„å­—æ®µ/å±�æ€§ï¼Œæ ‡è®°æ­¤å€¼+1ï¼Œ+2
    /// </summary>
    protected const int LastMKeyIndex = 1;

    [IgnoreDataMember]
    [MPIgnore, MP2Ignore]
#if __HAVE_N_JSON__
    [N_JsonIgnore]
#endif
#if !__NOT_HAVE_S_JSON__
    [S_JsonIgnore]
#endif
    public bool IsSuccess => mIsSuccess;

    /// <summary>
    /// ç”¨äº�åœ¨å®¢æˆ·ç«¯ä¸Šçºªå½•æœ¬æ¬¡è¯·æ±‚ä¸­å‡ºç�°çš„å¼‚å¸¸
    /// </summary>
    [IgnoreDataMember]
    [MPIgnore, MP2Ignore]
#if __HAVE_N_JSON__
    [N_JsonIgnore]
#endif
#if !__NOT_HAVE_S_JSON__
    [S_JsonIgnore]
#endif
    public Exception? ClientException { get; set; }

    /// <summary>
    /// ç”¨äº�åœ¨å®¢æˆ·ç«¯ä¸Šçºªå½•æœ¬æ¬¡è¯·æ±‚çš„ Url
    /// </summary>
    [IgnoreDataMember]
    [MPIgnore, MP2Ignore]
#if __HAVE_N_JSON__
    [N_JsonIgnore]
#endif
#if !__NOT_HAVE_S_JSON__
    [S_JsonIgnore]
#endif
    public string? Url { get; set; }
}