using LiteCqrs;
using TeleWave.Application.Common.Interfaces;
using TeleWave.Application.Common.Models;

namespace TeleWave.Application.Admin.Users.DeleteUser;

public sealed class DeleteUserCommandHandler(
    IIdentityService identityService,
    ICurrentUser currentUser
) : ICommandHandler<DeleteUserCommand, Result>
{
    public Task<Result> Handle(DeleteUserCommand command, CancellationToken cancellationToken)
    {
        if (currentUser.UserId == command.UserId)
            return Task.FromResult(Result.Failure(UserErrors.CannotDeleteSelf));

        return identityService.DeleteUserAsync(command.UserId, cancellationToken);
    }
}
