using System.Text.Json;
using System.Text.Json.Serialization;

namespace Kafka.Lib.Auth;

public class TokenValidationMessageType : IMessageType
{
    public string? Token { get; set; }
    public string? Mess { get; set; }

    public string? Id { get; set; }

    public string? EventType { get; } = "TokenNotValid";

    [JsonIgnore]
    public string Text
    {
        get => JsonSerializer.Serialize(this);
        set
        {
            if (!string.IsNullOrWhiteSpace(value))
            {
                var obj = JsonSerializer.Deserialize<TokenValidationMessageType>(value);

                if (obj != null)
                {
                    Token = obj.Token;
                    Mess = obj.Mess;
                }
            }
        }
    }
}