using EntitlementBLL.Auth; using EntitlementBLL.Interfaces; using EntitlementSL.Common; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using ErrorResponse = GB5Shared.Resource.Response.ErrorResponse; using static GB5Shared.GB5Constant.Constant; namespace EntitlementSL.Endpoints.ChangeRequest; // Any ClientAdmin — beta participation is not a commercial decision, so no additional capability // is required beyond the base admin tier (unlike RequestChangePlan/RequestRenewal). public class RequestBetaEnrol : BaseEndpoint> { private const string ClientJwtSchemeName = "ClientJwtBearer"; private readonly IChangeRequestBLL _ChangeRequestBLL; public RequestBetaEnrol(IChangeRequestBLL changeRequestBLL) => _ChangeRequestBLL = changeRequestBLL; public override void Configure() { Post("/lic/ChangeRequest.svc/RequestBetaEnrol"); AuthSchemes(ClientJwtSchemeName); Roles(ClientRoleCodes.ClientAdmin); } public record Body(string BetaProgramName, DateTime ValidUntil); public record Params( [property: FromHeader] string Login, [property: FromBody] Body RequestBody ); protected override string? GetCacheKey(Params req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync(Params req, LoginDTO loginDTO, CancellationToken ct) { var caller = ClientCallerContext.FromClaims(HttpContext.User.Claims); if (caller.Role != ClientRoleCodes.ClientAdmin || caller.ClientId <= 0) return await GB5Shared.ResponseStandard.Response.CreateErrorResponse( ErrorResponse.AccessDeniedMessage, CacheKeyLevel.NOT_REQUIRED, loginDTO, statusCode: 403); var changeRequestId = await _ChangeRequestBLL.SubmitBetaEnrolRequestAsync( caller.ClientId, req.RequestBody.BetaProgramName, req.RequestBody.ValidUntil, caller.ClientUserId, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( $"Beta enrol request submitted. ChangeRequestId={changeRequestId}", CacheKeyLevel.NOT_REQUIRED, loginDTO); } }