<?php
declare(strict_types=1);
namespace SHServ\Integrations\GAuth\Webhook;
use GNexus\GAuth\DTO\WebhookEvent;
use SHServ\Integrations\GAuth\Webhook\Handlers\UserHandler;
use SHServ\Integrations\GAuth\Webhook\Handlers\RoleHandler;
use SHServ\Integrations\GAuth\Webhook\Handlers\GroupHandler;
use SHServ\Integrations\GAuth\Webhook\Handlers\SessionHandler;
final class WebhookRouter
{
public function handle(WebhookEvent $event): void
{
$type = $event->eventType;
match (true) {
str_starts_with($type, 'user.') => (new UserHandler())->handle($event),
str_starts_with($type, 'client.roles_changed') => (new RoleHandler())->handle($event),
str_starts_with($type, 'client.permissions_changed') => (new RoleHandler())->handle($event),
str_starts_with($type, 'group.user_') => (new GroupHandler())->handle($event),
str_starts_with($type, 'auth.global_logout') => (new SessionHandler())->handle($event),
str_starts_with($type, 'session.revoked') => (new SessionHandler())->handle($event),
default => null,
};
}
}