namespace OpenNest.Data;
///
/// Wire shape of one material in the nest server's company material list, with its
/// grades. Names keep the spelling first added; matching uses .
///
public sealed class MaterialListEntry
{
public string Name { get; set; } = "";
public List Grades { get; set; } = new();
}
///
/// Body of an add to the company material list: a material and, optionally, one of its
/// grades. Adding a name or grade that is already listed (by key) changes nothing.
///
public sealed class MaterialListAddition
{
public string? Name { get; set; }
public string? Grade { get; set; }
}
public static class MaterialListRules
{
/// The first rule breaks, or null when it may be added.
public static string? GetError(MaterialListAddition? addition)
{
if (addition is null)
return "Missing material.";
if (SharedListNames.Key(addition.Name).Length == 0)
return "name is required.";
return DrawingLibraryRules.TextError("name", addition.Name, DrawingLibraryRules.MaxTextLength)
?? (addition.Grade is null ? null
: DrawingLibraryRules.TextError("grade", addition.Grade, DrawingLibraryRules.MaxTextLength));
}
/// The name as listed: trimmed, with internal whitespace runs collapsed to one space.
public static string Spelling(string? name) =>
name == null ? "" : string.Join(' ', name.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries));
}