using Dapr.Client; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MMDAL.DTO.MRPRun; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.MRPRun { // Triggers MPS (Type=0) followed by MRP (Type=1) sequentially. public class TriggerCombinedMRPRun : BaseEndpoint> { private readonly DaprClient _DaprClient; public TriggerCombinedMRPRun(DaprClient daprClient) => _DaprClient = daprClient; public override void Configure() { Post("/MRPRun/TriggerCombinedMRPRun"); AllowAnonymous(); } public record Params( [property: FromHeader] string Login, [property: FromBody] MRPRunTriggerDTO Trigger ); protected override string? GetCacheKey(Params req, LoginDTO login) => null; protected override async Task> ExecuteAsync( Params req, LoginDTO loginDTO, CancellationToken ct) { try { req.Trigger.WorkOUId = loginDTO.WorkOUId; req.Trigger.TenantId = loginDTO.ClientId; req.Trigger.UserId = loginDTO.UserId; req.Trigger.IsCombined = true; await _DaprClient.PublishEventAsync("pubsub", "mrprun.combined.trigger", req.Trigger, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( "Combined MPS + MRP run queued successfully.", CacheKeyLevel.NOT_REQUIRED, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 500); } } } }