using System.Text.Json;
using System.Text.Json.Serialization;
using Kafka.Lib.Auth.Model;

namespace Kafka.Lib.Auth;

public class PermisionChangeMassageType : IMessageType
{
    public PrivilageModel? PrivilageModel { get; set; }
    public Dictionary<string, string> Changes { get; set; } = new();

    public string? Id { get; set; }

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

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

                if (obj != null)
                {
                    PrivilageModel = obj.PrivilageModel;
                    Changes = obj.Changes;
                }
            }
        }
    }
}