<?php

declare(strict_types=1);

namespace ImovelZapAi\Authentication\Application\Actions;

use Illuminate\Http\Request;
use ImovelZapAi\Tenancy\Support\TenantContext;
use ImovelZapAi\Users\Infrastructure\Persistence\Eloquent\UserModel;

final class LogoutAction
{
    public function execute(Request $request): void
    {
        $user = $request->user();

        if ($user instanceof UserModel) {
            $user->currentAccessToken()?->delete();
        }

        TenantContext::clear();
    }
}
