using System.Globalization;
namespace SeaHaven.Services.Helpers
{
///
/// The board's exact work-order id filter: comma-separated positive integers, deduplicated,
/// at most distinct ids.
///
public static class WorkOrderIdSet
{
public const int MaxCount = 200;
///
/// Null when is absent or blank. Throws
/// (a 400 on the board) for any token that is not a positive integer, or too many ids.
///
public static IReadOnlyList? ParseOrThrow(string? raw)
{
if (string.IsNullOrWhiteSpace(raw))
return null;
var ids = new List();
var seen = new HashSet();
foreach (var token in raw.Split(','))
{
if (!int.TryParse(token.Trim(), NumberStyles.None, CultureInfo.InvariantCulture, out var id) || id <= 0)
throw new ArgumentException("ids must be a comma-separated list of positive work order ids.");
if (seen.Add(id))
ids.Add(id);
}
if (ids.Count > MaxCount)
throw new ArgumentException($"ids accepts at most {MaxCount} work orders.");
return ids;
}
}
}