using FastEndpoints;
using GB5Shared.DTO.Framework.Login;
using GB5Shared.DTO.Framework.ResponseStandard;
using GB5Shared.DTO.PubSub;
using GB5Shared.FastEndPoint;
using GB5Shared.PubSub.OutBox;
using static FrameworkDAL.Constant.Constant;
namespace FrameworkSL.Endpoints.Action
{
///
/// POST /Action/Resend
///
/// Re-publishes a TOUTBOX event so the action processor generates a fresh
/// notification email/WA message with new signed tokens.
///
/// Old un-clicked tokens remain valid until their 48-hour expiry but the
/// one-time-use check in ActionExecuteEndpoint prevents double execution
/// if both the original and resent tokens are clicked.
///
/// Body — :
/// EventTypeId — MEVENTTYPE.EVENTTYPEID for the notification to resend
/// ContextId — Entity PK (e.g. WorkflowTaskId, ServiceCallId)
///
public class ResendDirectAction
: BaseEndpoint>
{
private readonly IOutBox _outBox;
public ResendDirectAction(IOutBox outBox) => _outBox = outBox;
public override void Configure()
{
Post("/Action/Resend");
AllowAnonymous();
Description(b => b.WithTags("DirectAction"));
}
public record ResendDirectActionRequest(
[property: FromHeader] string Login,
[property: FromBody] ResendBody Body
);
public record ResendBody(int EventTypeId, int ContextId);
protected override string? GetCacheKey(ResendDirectActionRequest req, LoginDTO login) => null;
protected override async Task> ExecuteAsync(
ResendDirectActionRequest req,
LoginDTO login,
CancellationToken ct)
{
await _outBox.PublishEventAsync(new OutboxDTO
{
EventTypeId = req.Body.EventTypeId,
ObjectId = req.Body.ContextId,
Version = 1,
Payload = new { ContextId = req.Body.ContextId, ResendRequestedByUserId = login.UserId }
}, login, null!);
return await GB5Shared.ResponseStandard.Response
.CreateSuccessResponse("Resend queued successfully.", CacheKeyLevel.NotRequired, login);
}
}
}