<?php

declare(strict_types=1);

namespace apexl\Io\modules\user\Actions;

use apexl\Io\includes\HookManager;
use apexl\Io\modules\user\interfaces\SessionManagerInterface;

final readonly class LogoutAction
{
    public final const string HOOK__LOGOUT_BEFORE = 'logout.before';
    public final const string HOOK__LOGOUT_AFTER = 'logout.after';

    public function __construct(
        private HookManager $hookManager,
        private SessionManagerInterface $sessionManager
    ) {}


    public function handle(object $token): void
    {
        $this->hookManager->processHook(self::HOOK__LOGOUT_BEFORE, $token->sessionId);
        $this->sessionManager->endSession();
        $this->hookManager->processHook(self::HOOK__LOGOUT_AFTER);
    }
}