namespace NexusReader.Application.Utilities;

/// <summary>
/// Shared utility for parsing numeric segment identifiers from IDs like "seg-42".
/// Centralizes the parsing contract to avoid duplication across handlers and UI components.
/// </summary>
public static class SegmentIdParser
{
    /// <summary>
    /// Extracts the numeric portion from a segment identifier string (e.g., "seg-42" → 42).
    /// Returns 0 if the string is null, empty, or contains no digits.
    /// </summary>
    public static int Parse(string? id)
    {
        if (string.IsNullOrEmpty(id)) return 0;
        var digits = new string(id.Where(char.IsDigit).ToArray());
        return int.TryParse(digits, out var val) ? val : 0;
    }
}
