using System.Diagnostics;
using System.Text.Json.Serialization;
using Baya.SharedKernel.Extensions;

namespace Baya.Application.Models.ApiResult;

public class ApiResult
{
    public bool IsSuccess { get; set; }
    public ApiResultStatusCode StatusCode { get; set; }

    public string Message { get; set; }
    public string RequestId { get;  }

    /// <summary>Optional stable machine-readable error code (e.g. <c>otp_locked</c>) for a failure the client
    /// must branch on. Omitted from the wire when null, so success/normal responses are unchanged.</summary>
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    public string Code { get; set; }

    public ApiResult(bool isSuccess, ApiResultStatusCode statusCode, string message = null)
    {
        IsSuccess = isSuccess;
        StatusCode = statusCode;
        Message = message ?? statusCode.ToDisplay();
        RequestId = Activity.Current?.TraceId.ToHexString() ?? string.Empty;
    }

    
}

public class ApiResult<TData> : ApiResult

{
    public TData Data { get; set; }

    public ApiResult(bool isSuccess, ApiResultStatusCode statusCode, TData data, string message = null)
        : base(isSuccess, statusCode, message)
    {
        Data = data;
    }

    
}