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/GetPIETestTemplates?moduleId={guid}
///
/// Returns all active UAT scenarios for a PIE module as test templates.
/// Each template includes: Title, Preconditions, Steps (JSONB), ExpectedResult,
/// ComplexityLevel, LinkedVariantId, IsAutoGenerated.
///
/// Used by:
/// • TCMS ImportFromPIE — seeds MTCMSTESTCASE records with PIESCENID for traceability
/// • Angular pieqcmatrix/ test template panel
///
/// Cache: CLIENT_LEVEL.
/// Invalidated when MPIEUATSCENARIO changes (via SavePIEUATScenario if/when built).
///
public class GetPIETestTemplates : BaseEndpoint>
{
private readonly IPIEQcBLL _PIEQcBLL;
public GetPIETestTemplates(IPIEQcBLL pieQcBLL)
{
_PIEQcBLL = pieQcBLL;
}
public override void Configure()
{
Get("/PIE/QC/GetPIETestTemplates");
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.GetPIETestTemplatesAsync(req.ModuleId, loginDTO, ct);
return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(
result, CacheKeyLevel.CLIENT_LEVEL, loginDTO);
}
}