using System;
using Dalamud.Memory;
using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Component.GUI;
namespace Dalamud.Game.Addon;
///
/// This class represents a registered event that a plugin registers with a native ui node.
/// Contains all necessary information to track and clean up events automatically.
///
internal unsafe class AddonEventEntry
{
///
/// Name of an invalid addon.
///
public const string InvalidAddonName = "NullAddon";
private string? addonName;
///
/// Gets the pointer to the addons AtkUnitBase.
///
required public nint Addon { get; init; }
///
/// Gets the name of the addon this args referrers to.
///
public string AddonName => this.Addon == nint.Zero ? InvalidAddonName : this.addonName ??= MemoryHelper.ReadString((nint)((AtkUnitBase*)this.Addon)->Name, 0x20);
///
/// Gets the pointer to the event source.
///
required public nint Node { get; init; }
///
/// Gets the handler that gets called when this event is triggered.
///
required public IAddonEventManager.AddonEventHandler Handler { get; init; }
///
/// Gets the unique id for this event.
///
required public uint ParamKey { get; init; }
///
/// Gets the event type for this event.
///
required public AddonEventType EventType { get; init; }
///
/// Gets the event handle for this event.
///
required internal IAddonEventHandle Handle { get; init; }
///
/// Gets the formatted log string for this AddonEventEntry.
///
internal string LogString => $"ParamKey: {this.ParamKey}, Addon: {this.AddonName}, Event: {this.EventType}, GUID: {this.Handle.EventGuid}";
}