using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using TMSBLL.Assessment; using static GB5Shared.GB5Constant.Constant; namespace TMSSL.EndPoints.Assessment { // Returns DRAFT questions only — never auto-published into MASSESSMENTQUESTION. An admin // reviews/edits drafts in a separate screen and saves them via the existing // Assessment SaveQuestion path before they affect real scoring. Default implementation // (IAssessmentQuestionGenerationService's no-op) always returns an empty list; a real AI // service is registered later purely via DI, no endpoint change needed. public class GenerateQuestionsFromMaterial : BaseEndpoint> { private readonly IAssessmentQuestionGenerationService _GenerationService; public GenerateQuestionsFromMaterial(IAssessmentQuestionGenerationService generationService) { _GenerationService = generationService; } public override void Configure() { Post("/Assessment/GenerateQuestionsFromMaterial"); AllowAnonymous(); } public record Parameters( [property: FromBody] GenerateQuestionsRequestBody Body, [property: FromHeader] string Login ); public record GenerateQuestionsRequestBody(int ProgrammeId, string? MaterialReference, GenerationConfigDTO Config); protected override string? GetCacheKey(Parameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync(Parameters req, LoginDTO loginDTO, CancellationToken ct) { try { var drafts = await _GenerationService.GenerateQuestionsAsync(req.Body.ProgrammeId, req.Body.MaterialReference, req.Body.Config, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(drafts, CacheKeyLevel.NOT_REQUIRED, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 500); } } } }