using GB5Shared.DaprCache; using GB5Shared.DTO.Framework.Login; using Microsoft.Extensions.Logging; using PERMBLL.Interfaces; using PERMDAL.Interfaces; using static GB5Shared.GB5Constant.Constant; namespace PERMBLL.Implementations; public class PermConfigBLL : IPermConfigBLL { private readonly IPermConfigDAL _dal; private readonly ILogger _logger; // Default thresholds — used when no config row exists for a tenant private const decimal DefaultSelfWeight = 0.30m; // 30% private const decimal DefaultPIPThreshold = 40.0m; private const decimal DefaultTNAThreshold = 60.0m; public PermConfigBLL(IPermConfigDAL dal, ILogger logger) { _dal = dal; _logger = logger; } public async Task GetSelfWeightAsync(LoginDTO login, CancellationToken ct) { var raw = await _dal.GetConfigValueAsync("SelfWeightDefault", login, ct).ConfigureAwait(false); if (decimal.TryParse(raw, out decimal value)) return value / 100m; // stored as 30, returned as 0.30 _logger.LogWarning("SelfWeightDefault not configured for tenant {ClientId}, using default", login.ClientId); return DefaultSelfWeight; } public async Task GetPIPThresholdAsync(LoginDTO login, CancellationToken ct) { var raw = await _dal.GetConfigValueAsync("PIPTriggerThreshold", login, ct).ConfigureAwait(false); if (decimal.TryParse(raw, out decimal value)) return value; return DefaultPIPThreshold; } public async Task GetTNAThresholdAsync(LoginDTO login, CancellationToken ct) { var raw = await _dal.GetConfigValueAsync("TNAGapThreshold", login, ct).ConfigureAwait(false); if (decimal.TryParse(raw, out decimal value)) return value; return DefaultTNAThreshold; } }