using PnvPanel.Application.Auth; using PnvPanel.Application.Common.Interfaces; using PnvPanel.Application.Common.Messaging; using PnvPanel.Application.Common.Models; using PnvPanel.Domain.Telegram; namespace PnvPanel.Application.Telegram; public sealed class CreateLinkTokenCommandHandler(IAppDbContext dbContext, ICurrentUser currentUser) : ICommandHandler> { private static readonly TimeSpan Ttl = TimeSpan.FromMinutes(5); public Task> Handle(CreateLinkTokenCommand command, CancellationToken cancellationToken) { if (currentUser.UserId is not { } userId) return Task.FromResult(Result.Failure(AuthErrors.Unauthorized)); var token = TelegramLinkToken.Create(userId, Ttl); dbContext.TelegramLinkTokens.Add(token); return Task.FromResult(Result.Success(new LinkTokenDto(token.Token, token.ExpiresAt))); } }