const PROTOCOL_LABELS: Record<string, string> = {
  GB32960: 'GB/T 32960',
  JT808: 'JT/T 808',
  YUTONG_MQTT: '宇通 MQTT'
};

export function protocolDisplayLabel(protocol?: string) {
  const normalized = protocol?.trim() ?? '';
  return normalized ? PROTOCOL_LABELS[normalized] ?? normalized : '—';
}

export function protocolSourceLabel(source?: string) {
  const normalized = source?.trim() ?? '';
  if (!normalized) return '';
  const separator = normalized.indexOf(':');
  if (separator < 0) return protocolDisplayLabel(normalized);
  const protocol = normalized.slice(0, separator);
  const qualifier = normalized.slice(separator + 1);
  const label = protocolDisplayLabel(protocol);
  return label === protocol ? normalized : qualifier ? `${label} · ${qualifier}` : label;
}
