using FrameworkDAL.DTO.EIPConversation; using FrameworkDAL.Query.EIPConversation.EIPSession; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using System; using System.Threading; using System.Threading.Tasks; namespace FrameworkDAL.CustomCode.EIPConversation.EIPSession { public class EIPSessionDAL : IEIPSessionDAL { private readonly IQueryExecutor _qe; public EIPSessionDAL(IQueryExecutor qe) => _qe = qe; public async Task GetActiveSessionAsync( string userIdentifier, int tenantId, int channelType, LoginDTO login, CancellationToken ct = default) { return await _qe.QuerySingleAsync( login, EIPSessionQB.GET_ACTIVE_SESSION, new { UserIdentifier = userIdentifier, TenantId = tenantId, ChannelType = channelType }, cancellationToken: ct).ConfigureAwait(false); } public async Task UpsertSessionAsync( EIPUserSessionDTO session, LoginDTO login, CancellationToken ct = default) { // SessionId is pre-generated in C# so we know it for INSERT. // OUTPUT INSERTED.SESSIONID returns the actual GUID for both // INSERT (new) and UPDATE (existing) cases. var result = await _qe.QuerySingleAsync( login, EIPSessionQB.UPSERT_SESSION, new { SessionId = session.SessionId, session.UserIdentifier, session.TenantId, session.ChannelType, session.FlowCode, session.CurrentStepCode, session.ContextJson }, cancellationToken: ct).ConfigureAwait(false); return result?.SessionId ?? session.SessionId; } public async Task ExpireSessionAsync( string userIdentifier, int tenantId, int channelType, LoginDTO login, CancellationToken ct = default) { await _qe.ExecuteAsync( login, EIPSessionQB.EXPIRE_SESSION, new { UserIdentifier = userIdentifier, TenantId = tenantId, ChannelType = channelType }, cancellationToken: ct).ConfigureAwait(false); } } }