using System;
using System.Collections.Generic;
using System.Linq;
namespace OpenNest;
/// One material/unit system's requirements. Collections are copied; all nested values are immutable.
public sealed class NestJob
{
public NestJob(IEnumerable parts, IEnumerable plates, NestJobOptions options = null)
{
Parts = Own(parts);
Plates = Own(plates);
Options = options ?? new NestJobOptions();
if (Parts.Select(p => p.Id).Distinct(StringComparer.Ordinal).Count() != Parts.Count ||
Plates.Select(p => p.Id).Distinct(StringComparer.Ordinal).Count() != Plates.Count)
throw new ArgumentException("Part and stock IDs must each be unique.");
}
public IReadOnlyList Parts { get; }
public IReadOnlyList Plates { get; }
public NestJobOptions Options { get; }
internal static IReadOnlyList Own(IEnumerable source)
{
ArgumentNullException.ThrowIfNull(source);
var values = source.ToArray();
if (values.Any(value => value is null))
throw new ArgumentException("Null entries are not allowed.", nameof(source));
return Array.AsReadOnly(values);
}
}