using FastEndpoints;
using GB5Shared.DTO.Framework.Login;
using GB5Shared.DTO.Framework.ResponseStandard;
using GB5Shared.FastEndPoint;
using PIEBLL.QC;
using static GB5Shared.GB5Constant.Constant;
namespace PIESL.EndPoints.QC;
///
/// GET /PIE/QC/GetPIEBehaviorMatrix?moduleId={guid}
///
/// Returns the full behavior matrix for a PIE module:
/// - Header: ModuleId, ModuleName, TotalBehaviors, TotalConfigItems
/// - Rows: one per active variant with ImplicationCount, TotalEffortDelta, HasRiskNotes
///
/// Used by:
/// • Angular pieqcmatrix/ component (existing — just needs this endpoint)
/// • TCMS coverage analysis (variant coverage gap detection)
///
/// Cache: CLIENT_LEVEL — shared across users of same tenant.
/// Invalidated when MPIEVARIANT or MPIEVARIANTIMPLICATION changes (via SavePIEVariant).
///
public class GetPIEBehaviorMatrix : BaseEndpoint>
{
private readonly IPIEQcBLL _PIEQcBLL;
public GetPIEBehaviorMatrix(IPIEQcBLL pieQcBLL)
{
_PIEQcBLL = pieQcBLL;
}
public override void Configure()
{
Get("/PIE/QC/GetPIEBehaviorMatrix");
AllowAnonymous();
}
public record Params(
[property: FromHeader] string Login,
[property: QueryParam] Guid ModuleId
);
protected override string? GetCacheKey(Params req, LoginDTO loginDTO)
=> KeyGenerator.KeyGeneration(
req.ModuleId,
EntityConstant.OBJECTPIEQC,
CacheKeyLevel.CLIENT_LEVEL,
loginDTO);
protected override async Task> ExecuteAsync(
Params req, LoginDTO loginDTO, CancellationToken ct)
{
var result = await _PIEQcBLL.GetPIEBehaviorMatrixAsync(req.ModuleId, loginDTO, ct);
return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(
result, CacheKeyLevel.CLIENT_LEVEL, loginDTO);
}
}