using Microsoft.EntityFrameworkCore.Storage; using Microsoft.Extensions.Logging; using SVSim.Database.Enums; using SVSim.Database.Models; using SVSim.Database.Models.Config; namespace SVSim.Database.Services.Inventory; internal sealed class InventoryTransaction : IInventoryTransaction { private readonly SVSimDbContext _db; private readonly IDbContextTransaction _dbTx; private readonly ILogger _log; private readonly FreeplayConfig _freeplay; private bool _committed; public Viewer Viewer { get; } public bool IsFreeplay => _freeplay.Enabled; public InventoryTransaction( SVSimDbContext db, IDbContextTransaction dbTx, Viewer viewer, FreeplayConfig freeplay, ILogger log) { _db = db; _dbTx = dbTx; Viewer = viewer; _freeplay = freeplay; _log = log; } // Implementations land in later tasks. Throw NotImplementedException to keep the build green. public Task TrySpendAsync(SpendCurrency currency, long cost, CancellationToken ct = default) => throw new NotImplementedException(); public Task TryDebitAsync(UserGoodsType type, long detailId, int num, CancellationToken ct = default) => throw new NotImplementedException(); public Task> GrantAsync(UserGoodsType type, long detailId, int num, CancellationToken ct = default) => throw new NotImplementedException(); public Task BackfillCardCosmeticsAsync(CancellationToken ct = default) => throw new NotImplementedException(); public long EffectiveBalance(SpendCurrency currency) => throw new NotImplementedException(); public bool OwnsCard(long cardId) => throw new NotImplementedException(); public bool OwnsCosmetic(CosmeticType type, int id) => throw new NotImplementedException(); public Task CommitAsync(CancellationToken ct = default) => throw new NotImplementedException(); public async ValueTask DisposeAsync() { if (!_committed) { await _dbTx.RollbackAsync(); _db.ChangeTracker.Clear(); } await _dbTx.DisposeAsync(); } }