namespace SVSim.Database.Repositories.Card; /// /// Mutating operations on a viewer's card inventory (destruct, create, protect…). /// Read-only catalog queries live on . /// public interface ICardInventoryRepository { /// /// Validate-then-mutate destruct of owned cards. Atomic: all validation runs before any /// mutation, and the mutation phase is wrapped in an explicit DB transaction so a mid-flight /// EF failure rolls back currency + inventory + deck-strip together. /// /// Authenticated viewer. /// cardId → num_to_destruct. Empty dict is rejected by the caller. /// /// with post-state totals on success, or a /// when validation fails. On error nothing is written. /// Task DestructCards(long viewerId, IReadOnlyDictionary destructCounts); } /// /// Either a success payload or an error code. Discriminated by which field is set. /// public sealed record DestructOutcome(DestructResult? Result, DestructError? Error) { public bool IsSuccess => Result is not null; public static DestructOutcome Ok(DestructResult r) => new(r, null); public static DestructOutcome Fail(DestructError e) => new(null, e); } public sealed record DestructResult( ulong NewRedEtherTotal, IReadOnlyDictionary NewOwnedCounts); // cardId → post-destruct Count public enum DestructError { UnknownCard, NotDestructible, CardProtected, InsufficientCards, }