using System; using System.Collections.Generic; using System.Linq; using BoundaryLab.Domain; namespace BoundaryLab.Application; public interface IReservationStore { InventoryState Current { get; } bool TryCommit(InventoryState expected, InventoryState next, ReservationNotice notice); } public sealed class ReservationWorkflow(IReservationStore store) { public bool Reserve(int units) { var before = store.Current; var after = before.Reserve(units); return after is not null && store.TryCommit(before, after, new ReservationNotice(after.Version, units)); } }