Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Claudio Schaad <c.schaad@pog.ch> Co-committed-by: Claudio Schaad <c.schaad@pog.ch>
27 lines
827 B
C#
27 lines
827 B
C#
using Schaad.OpenData.Watercraft.Models;
|
|
|
|
namespace Schaad.OpenData.Watercraft.Storage;
|
|
|
|
public sealed class WatercraftSnapshot
|
|
{
|
|
public static readonly WatercraftSnapshot Empty = new([], null);
|
|
|
|
public WatercraftSnapshot(IEnumerable<VesselYear> years, DateTimeOffset? lastRefresh)
|
|
{
|
|
Years = years
|
|
.GroupBy(y => y.Year)
|
|
.Select(g => g.Last())
|
|
.OrderBy(y => y.Year)
|
|
.ToList();
|
|
LastRefresh = lastRefresh;
|
|
}
|
|
|
|
public IReadOnlyList<VesselYear> Years { get; }
|
|
|
|
public DateTimeOffset? LastRefresh { get; }
|
|
|
|
public VesselYear? FindYear(int year) => Years.FirstOrDefault(y => y.Year == year);
|
|
|
|
public WatercraftSnapshot With(IEnumerable<VesselYear> changed, DateTimeOffset lastRefresh) =>
|
|
new(Years.Concat(changed), lastRefresh);
|
|
}
|