using System.Text.Json;

namespace Kafka.Lib.Warehouse;

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

    public string? Id { get; set; }

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

    public string Text
    {
        get
        {
            return JsonSerializer.Serialize(this);
        }
        set
        {
            if (string.IsNullOrEmpty(value))
            {
                var obj = JsonSerializer.Deserialize<ProducerChangeMessageType>(value);

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