using System.Data.Common; using EntitlementDAL.DTOs; using EntitlementDAL.Interfaces; using EntitlementDAL.QueryBuilders; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; namespace EntitlementDAL.Implementations; public class BundleDAL : IBundleDAL { private readonly IQueryExecutor _QueryExecutor; public BundleDAL(IQueryExecutor queryExecutor) => _QueryExecutor = queryExecutor; public async Task GetCurrentByClientAsync(int clientId, LoginDTO login, CancellationToken ct) => await _QueryExecutor.QuerySingleAsync( login, BundleQB.GET_CURRENT_BY_CLIENT, new { ClientId = clientId }, cancellationToken: ct).ConfigureAwait(false); public async Task GetByIdAsync(int bundleId, LoginDTO login, CancellationToken ct) => await _QueryExecutor.QuerySingleAsync( login, BundleQB.GET_BY_ID, new { BundleId = bundleId }, cancellationToken: ct).ConfigureAwait(false); public async Task ExpirePriorCurrentAsync(int clientId, LoginDTO login, DbTransaction tx, CancellationToken ct) => await _QueryExecutor.ExecuteAsync(login, BundleQB.EXPIRE_PRIOR_CURRENT, new { ClientId = clientId, ModifiedById = login.UserId, ModifiedOn = DateTime.UtcNow }, tx, cancellationToken: ct).ConfigureAwait(false); public async Task SaveAsync(BundleDTO dto, LoginDTO login, DbTransaction tx, CancellationToken ct) => await _QueryExecutor.ExecuteAsync(login, BundleQB.INSERT, dto, tx, cancellationToken: ct).ConfigureAwait(false); public async Task> GetExpiringSoonAsync(DateTime cutoffDate, LoginDTO login, CancellationToken ct) => await _QueryExecutor.QueryAsync( login, BundleQB.GET_EXPIRING_SOON, new { CutoffDate = cutoffDate }, cancellationToken: ct).ConfigureAwait(false) ?? Enumerable.Empty(); }