using EnablementDAL.CustomCode.ShowResolver; using EnablementDAL.DTO; using EnablementDAL.Query.Show; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; namespace EnablementDAL.Implementations; public class ShowResolverDAL : IShowResolverDAL { private readonly IQueryExecutor _qe; public ShowResolverDAL(IQueryExecutor qe) => _qe = qe; // ------------------------------------------------------------------------- // Candidate shows: active + approved + within date range for this tenant/startType. // Parameters: @TenantId, @StartType // ------------------------------------------------------------------------- public async Task> GetCandidateShowsAsync( int startType, LoginDTO login, CancellationToken ct) => await _qe.QueryAsync( login, ShowResolverQB.GET_CANDIDATE_SHOWS, new { TenantId = login.ClientId, StartType = startType }, cancellationToken: ct).ConfigureAwait(false); // ------------------------------------------------------------------------- // Candidate shows for the MATCH resolver (ResolveShowMatches) — continuous/ // pull surface, no StartType filter. Parameters: @TenantId // ------------------------------------------------------------------------- public async Task> GetCandidateShowsForMatchAsync( LoginDTO login, CancellationToken ct) => await _qe.QueryAsync( login, ShowResolverQB.GET_CANDIDATE_SHOWS_FOR_MATCH, new { TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); // ------------------------------------------------------------------------- // All active resolver rules (scope / audience / trigger) for this tenant. // Parameters: @TenantId // ------------------------------------------------------------------------- public async Task> GetShowRulesAsync( LoginDTO login, CancellationToken ct) => await _qe.QueryAsync( login, ShowResolverQB.GET_SHOW_RULES, new { TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); // ------------------------------------------------------------------------- // Active schedules for all active shows in this tenant. // Parameters: @TenantId // ------------------------------------------------------------------------- public async Task> GetShowSchedulesAsync( LoginDTO login, CancellationToken ct) => await _qe.QueryAsync( login, ShowResolverQB.GET_SHOW_SCHEDULES, new { TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); // ------------------------------------------------------------------------- // Shows already completed or dismissed by this user (for OneTime exclusion). // FIX: was missing TenantId — added login.ClientId. // Parameters: @UserId, @TenantId // ------------------------------------------------------------------------- public async Task> GetUserCompletedRunShowIdsAsync( int userId, LoginDTO login, CancellationToken ct) => await _qe.QueryAsync( login, ShowResolverQB.GET_USER_COMPLETED_RUNS, new { UserId = userId, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); // ------------------------------------------------------------------------- // Returns true if this user has zero run records (first login ever). // FIX: was missing TenantId — added login.ClientId. // Parameters: @UserId, @TenantId // ------------------------------------------------------------------------- public async Task IsFirstLoginAsync( int userId, LoginDTO login, CancellationToken ct) { int count = await _qe.ExecuteScalarAsync( login, ShowResolverQB.CHECK_FIRST_LOGIN, new { UserId = userId, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); return count == 0; } public async Task> GetStepContentAsync( IEnumerable showIds, LoginDTO login, CancellationToken ct) { if (!showIds.Any()) return Enumerable.Empty(); return await _qe.QueryAsync( login, ShowResolverQB.GET_STEP_CONTENT, new { ShowIds = showIds }, cancellationToken: ct).ConfigureAwait(false); } }