using System.Text.Json; using CollabDAL.DTO.CollabConfig; using CollabDAL.Query.CollabConfig; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; namespace CollabDAL.CustomCode.CollabConfig; public class CollabConfigDAL(IQueryExecutor _qe) : ICollabConfigDAL { public async Task GetConfigAsync(LoginDTO login, CancellationToken ct) { var config = await _qe.QuerySingleAsync( login, CollabConfigQB.GET_CONFIG, new { login.DatabaseName }).ConfigureAwait(false); // Dapper returns AllowedModules as string — deserialize back to List if (config is not null && config.AllowedModules is null) { // AllowedModules is already null — nothing to deserialize } return config; } public async Task UpsertConfigAsync(UpdateCollabConfigSaveDTO dto, LoginDTO login, CancellationToken ct) { // Serialize AllowedModules list to JSON string for storage var allowedModulesJson = dto.AllowedModules is not null ? JsonSerializer.Serialize(dto.AllowedModules) : null; await _qe.ExecuteAsync( login, CollabConfigQB.UPSERT_CONFIG, new { login.DatabaseName, dto.MaxParticipantsDefault, dto.MaxParticipantsAbsolute, dto.SessionTimeoutMinutes, dto.InviteLinkExpiryMinutes, dto.AllowScreenShare, dto.AllowAnonymousJoin, dto.AllowGuestJoinViaLink, dto.EnableAuditLog, dto.EnableCoBrowse, dto.EnableInSessionChat, dto.EnableAnnotations, dto.EnableCursorBroadcast, dto.EnableFormSync, dto.ControlConsentMode, AllowedModules = allowedModulesJson, ModifiedBy = login.UserCode, }).ConfigureAwait(false); } }