using System.Linq;
using GB5Shared.DTO.Framework.Login;
using GB5Shared.QueryExecutor;
using RecruitmentDAL.DTO.Integration;
using RecruitmentDAL.Query.Integration;
namespace RecruitmentDAL.CustomeCode.Integration
{
///
public class UserLookupDAL : IUserLookupDAL
{
private readonly IQueryExecutor _QueryExecutor;
public UserLookupDAL(IQueryExecutor queryExecutor)
{
_QueryExecutor = queryExecutor;
}
public async Task GetUserEmail(int userId, LoginDTO loginDTO, CancellationToken ct)
{
// QueryAsync + FirstOrDefault, not QuerySingleAsync — a UserId that no longer exists
// or was never resolved must degrade to "no email" rather than throw (CLAUDE.md:
// QuerySingleOrDefaultAsync does not exist on IQueryExecutor).
var rows = await _QueryExecutor
.QueryAsync(loginDTO, UserLookupQB.GET_USER_EMAIL, new { UserId = userId }, cancellationToken: ct)
.ConfigureAwait(false);
return rows.FirstOrDefault()?.PrimaryMail;
}
}
}