using Application.Abstractions.Messaging; using Application.Abstractions.YouTube; using SharedKernel.Results; namespace Application.Features.Admin.Channel.YouTubePubSub.ManualDetect; internal sealed class Handler( IMediator mediator, IYouTubePubSubService pubSubService ) : ICommandHandler { public async Task Handle(Command request, CancellationToken ct) { if (string.IsNullOrWhiteSpace(request.VideoID) || string.IsNullOrWhiteSpace(request.YouTubeChannelID)) { return Result.Failure(Error.Problem("YouTubePubSub.ManualDetectInvalid", "Video ID와 YouTube Channel ID가 필요합니다.")); } // 수동 트리거는 dedupe 마커를 먼저 제거해서 재처리 가능하게 함 // (이미 한번 처리했어도 다시 감지 시도) await pubSubService.SetLastProcessedVideoIdAsync(request.YouTubeChannelID, string.Empty, ct); await mediator.Send(new Application.Features.Api.YouTube.PubSubNotify.Command( request.VideoID, request.YouTubeChannelID, string.Empty, DateTime.UtcNow, DateTime.UtcNow ), ct); return Result.Success(); } }