using System.Text.Json;
using Kafka.Lib.Warehouse.Model;

namespace Kafka.Lib.Warehouse;

public class InventoryChangeMessageType : IMessageType
{
    public int ChangeRecordCount { get; set; }
    public List<InventoryChangeModel> InventoryChanges { get; set; } = new();

    public string? Id { get; set; }

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

    public string Text
    {
        get => JsonSerializer.Serialize(this);
        set
        {
            if (string.IsNullOrEmpty(value))
            {
                var obj = JsonSerializer.Deserialize<InventoryChangeMessageType>(value);
                if (obj != null)
                {
                    InventoryChanges = obj.InventoryChanges;
                    ChangeRecordCount = obj.ChangeRecordCount;
                }
            }
        }
    }
}