Card liquefication
This commit is contained in:
44
SVSim.Database/Repositories/Card/ICardInventoryRepository.cs
Normal file
44
SVSim.Database/Repositories/Card/ICardInventoryRepository.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
namespace SVSim.Database.Repositories.Card;
|
||||
|
||||
/// <summary>
|
||||
/// Mutating operations on a viewer's card inventory (destruct, create, protect…).
|
||||
/// Read-only catalog queries live on <see cref="ICardRepository"/>.
|
||||
/// </summary>
|
||||
public interface ICardInventoryRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="viewerId">Authenticated viewer.</param>
|
||||
/// <param name="destructCounts">cardId → num_to_destruct. Empty dict is rejected by the caller.</param>
|
||||
/// <returns>
|
||||
/// <see cref="DestructResult"/> with post-state totals on success, or a
|
||||
/// <see cref="DestructError"/> when validation fails. On error nothing is written.
|
||||
/// </returns>
|
||||
Task<DestructOutcome> DestructCards(long viewerId, IReadOnlyDictionary<long, int> destructCounts);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Either a success payload or an error code. Discriminated by which field is set.
|
||||
/// </summary>
|
||||
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<long, int> NewOwnedCounts); // cardId → post-destruct Count
|
||||
|
||||
public enum DestructError
|
||||
{
|
||||
UnknownCard,
|
||||
NotDestructible,
|
||||
CardProtected,
|
||||
InsufficientCards,
|
||||
}
|
||||
Reference in New Issue
Block a user