using System.Text.Json;

namespace Kafka.Lib.Warehouse;

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

    public string? Id { get; set; }

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

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

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