using Schaad.OpenData.Watercraft.Models; namespace Schaad.OpenData.Watercraft.Storage; public sealed class WatercraftSnapshot { public static readonly WatercraftSnapshot Empty = new([], null); public WatercraftSnapshot(IEnumerable years, DateTimeOffset? lastRefresh) { Years = years .GroupBy(y => y.Year) .Select(g => g.Last()) .OrderBy(y => y.Year) .ToList(); LastRefresh = lastRefresh; } public IReadOnlyList Years { get; } public DateTimeOffset? LastRefresh { get; } public VesselYear? FindYear(int year) => Years.FirstOrDefault(y => y.Year == year); public WatercraftSnapshot With(IEnumerable changed, DateTimeOffset lastRefresh) => new(Years.Concat(changed), lastRefresh); }