namespace ZB.MOM.WW.OtOpcUa.AdminUI.Uns.TagEditors;

/// <summary>
/// Maps a driver's <c>DriverType</c> string to its typed tag-config editor component (mirrors
/// <c>DriverEditRouter._componentMap</c>). Drivers absent from the map fall back to the generic
/// raw-JSON textarea in the TagModal.
/// </summary>
public static class TagConfigEditorMap
{
    private static readonly IReadOnlyDictionary<string, Type> Map =
        new Dictionary<string, Type>(StringComparer.OrdinalIgnoreCase)
        {
            ["ModbusTcp"] = typeof(Components.Shared.Uns.TagEditors.ModbusTagConfigEditor),
            ["S7"]        = typeof(Components.Shared.Uns.TagEditors.S7TagConfigEditor),
            ["AbCip"]     = typeof(Components.Shared.Uns.TagEditors.AbCipTagConfigEditor),
            ["AbLegacy"]  = typeof(Components.Shared.Uns.TagEditors.AbLegacyTagConfigEditor),
            ["TwinCat"]   = typeof(Components.Shared.Uns.TagEditors.TwinCATTagConfigEditor),
            ["Focas"]     = typeof(Components.Shared.Uns.TagEditors.FocasTagConfigEditor),
        };

    /// <summary>Returns the editor component type for a driver type, or null if none is registered.</summary>
    public static Type? Resolve(string? driverType)
        => driverType is not null && Map.TryGetValue(driverType, out var t) ? t : null;
}
