namespace TuneBoss.Core.Models;
///
/// Converts raw config field identifiers into human-readable display text:
/// underscores become spaces, and engineering shortforms expand to their meaning
/// (e.g. RPM_Limit_div100 → "RPM Limit (divided by 100)",
/// Fuel_Max_PW_Mult → "Fuel Max Pulse Width Multiplier").
/// Unknown tokens pass through unchanged, so new fields degrade gracefully.
///
public static class MiscDisplayText
{
// Case-insensitive single-token expansions.
private static readonly Dictionary Map = new(StringComparer.OrdinalIgnoreCase)
{
// scaling / units
["div100"] = "(divided by 100)",
["div10"] = "(divided by 10)",
["div5"] = "(divided by 5)",
["x10"] = "(times 10)",
["x100"] = "(times 100)",
["ms"] = "(in milliseconds)",
["5ms"] = "(in 5 ms steps)",
["10ms"] = "(in 10 ms steps)",
["100ms"] = "(in 100 ms steps)",
["us"] = "(in microseconds)",
["degC"] = "(in Celsius degrees)",
["deg"] = "(in degrees)",
["kph"] = "(in km/h)",
["kmh"] = "(in km/h)",
["pct"] = "Percent",
["raw"] = "(raw)",
// engineering shortforms
["PW"] = "Pulse Width",
["Decel"] = "Deceleration",
["Accel"] = "Acceleration",
["Etemp"] = "Engine Temperature",
["VBAT"] = "Battery Voltage",
["IAT"] = "Intake Air Temperature",
["BARO"] = "Barometric",
["NOS"] = "Nitrous",
["ISM"] = "Idle Stepper Motor",
["AIS"] = "Air Induction System",
["O2H"] = "O2 Heater",
["FC"] = "Fuel Consumption",
["PerSec"] = "Per Second",
["Hi"] = "High",
["Lo"] = "Low",
["Neg"] = "Negative",
["Pos"] = "Positive",
["Mult"] = "Multiplier",
["Div"] = "Divider",
["Num"] = "Number",
["Init"] = "Initial",
["Cfg"] = "Config",
["Ctrl"] = "Control",
["Rsvd"] = "Reserved",
["Isol"] = "Idle Solenoid",
["Ref"] = "Reference",
["Retard"] = "Retard",
["Solenoid"] = "Solenoid",
["Samplepoint"] = "Sample Point",
};
// Case-SENSITIVE tokens (too dangerous to match loosely).
private static readonly Dictionary ExactMap = new(StringComparer.Ordinal)
{
["s"] = "(in seconds)",
};
// Multi-token sequences consumed together (checked before single tokens).
private static readonly (string A, string B, string Text)[] Pairs =
{
("ms", "div5", "(in milliseconds, divided by 5)"),
("ms", "div10", "(in milliseconds, divided by 10)"),
};
private static readonly Dictionary Cache = new();
/// Display text for a raw field identifier.
public static string For(string raw)
{
if (string.IsNullOrEmpty(raw)) return raw;
lock (Cache)
{
if (Cache.TryGetValue(raw, out var hit)) return hit;
}
var tokens = raw.Split('_', StringSplitOptions.RemoveEmptyEntries);
var outParts = new List(tokens.Length);
for (int i = 0; i < tokens.Length; i++)
{
bool paired = false;
if (i + 1 < tokens.Length)
{
foreach (var (a, b, text) in Pairs)
{
if (tokens[i].Equals(a, StringComparison.OrdinalIgnoreCase) &&
tokens[i + 1].Equals(b, StringComparison.OrdinalIgnoreCase))
{
outParts.Add(text);
i++; // consume both
paired = true;
break;
}
}
}
if (paired) continue;
if (ExactMap.TryGetValue(tokens[i], out var exact)) outParts.Add(exact);
else if (Map.TryGetValue(tokens[i], out var mapped)) outParts.Add(mapped);
else outParts.Add(tokens[i]);
}
var result = string.Join(" ", outParts);
lock (Cache) { Cache[raw] = result; }
return result;
}
}