using Dalamud.Plugin.Services;
using Dalamud.Plugin;
using OtterGui.Log;
using Penumbra.GameData.Data;
using System.Collections.Frozen;
using System.Diagnostics.CodeAnalysis;
using CustomizePlus.GameData.ReverseSearchDictionaries.Bases;
using Lumina.Excel.Sheets;
namespace CustomizePlus.GameData.ReverseSearchDictionaries;
/// A dictionary that matches names to event npc ids.
public sealed class ReverseSearchDictENpc(IDalamudPluginInterface pluginInterface, Logger log, IDataManager gameData)
: ReverseNameDictionary(pluginInterface, log, gameData, "ReverseSearchENpcs", Versions.DictENpc, () => CreateENpcData(gameData))
{
/// Create the data.
private static IReadOnlyDictionary CreateENpcData(IDataManager gameData)
{
var sheet = gameData.GetExcelSheet(gameData.Language)!;
var dict = new Dictionary((int)sheet.Count);
foreach (var n in sheet.Where(e => e.Singular.ByteLength > 0))
dict.TryAdd(DataUtility.ToTitleCaseExtended(n.Singular, n.Article), n.RowId);
return dict.ToFrozenDictionary();
}
///
public bool TryGetValue(string key, [NotNullWhen(true)] out uint value)
=> Value.TryGetValue(key, out value);
///
public uint this[string key]
=> Value[key];
}