using CollabDAL.CustomCode.CollabConfig; using CollabDAL.DTO.CollabConfig; using GB5Shared.DaprCache; using GB5Shared.DTO.Framework.Login; using GB5Shared.EventLogPublish; using GB5Shared.GB5Constant; using Microsoft.Extensions.Logging; using Newtonsoft.Json; namespace CollabBLL.CollabConfig; public class CollabConfigBLL( ICollabConfigDAL _configDal, KeyInvalidate _keyInvalidate, EventLogPublish _eventLog, ILogger _logger ) : ICollabConfigBLL { // ── GET CONFIG ──────────────────────────────────────────────────── public async Task GetConfigAsync(LoginDTO login, CancellationToken ct) { var config = await _configDal.GetConfigAsync(login, ct).ConfigureAwait(false) ?? CollabConfigDTO.Default; return JsonConvert.SerializeObject(config.ToClientDTO()); } // ── UPDATE CONFIG ───────────────────────────────────────────────── public async Task UpdateConfigAsync( UpdateCollabConfigSaveDTO dto, LoginDTO login, CancellationToken ct) { if (dto.MaxParticipantsDefault <= 0) throw new InvalidOperationException("MaxParticipantsDefault must be greater than zero."); if (dto.MaxParticipantsAbsolute < dto.MaxParticipantsDefault) throw new InvalidOperationException("MaxParticipantsAbsolute must be >= MaxParticipantsDefault."); if (dto.SessionTimeoutMinutes <= 0) throw new InvalidOperationException("SessionTimeoutMinutes must be greater than zero."); if (dto.InviteLinkExpiryMinutes <= 0) throw new InvalidOperationException("InviteLinkExpiryMinutes must be greater than zero."); await _configDal.UpsertConfigAsync(dto, login, ct).ConfigureAwait(false); await _eventLog.PublishEventLogAsync( "Collaboration Config Updated", dto, Constant.EventTypeConstant.SAVEDOCUMENTSET, 0, login).ConfigureAwait(false); var cacheKey = new CacheKeyGeneration().KeyGeneration( login.DatabaseName, Constant.EntityConstant.OBJECTCOLLABCONFIG, Constant.CacheKeyLevel.CLIENT_LEVEL, login); await _keyInvalidate.InvalidateCache(cacheKey).ConfigureAwait(false); return JsonConvert.SerializeObject(new { Success = true }); } }