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

namespace Kafka.Lib.Auth;

public class RegisterNewServiceMessageType : IMessageType
{
    public string? ServiceName { get; set; }
    public string? ServiceAccountUserName { get; set; }
    public List<string>? ServicePrivilage { get; set; }

    public string? Id { get; set; }

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

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

                if (obj != null)
                {
                    ServiceName = obj.ServiceName;
                    ServiceAccountUserName = obj.ServiceAccountUserName;
                    ServicePrivilage = obj.ServicePrivilage;
                }
            }
        }
    }
}