<?php

declare(strict_types=1);

namespace App\EventSubscriber;

use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonFromUserItemPostEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class PersonFromUserItemSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            PersonFromUserItemPostEvent::NAME => 'onPost',
        ];
    }

    public function onPost(PersonFromUserItemPostEvent $event)
    {
        $person = $event->getPerson();

        $roles = ['ROLE_SCOPE_OFFICIAL-SIGNATURE'];
        $person->setExtraData('ldap-roles', $roles);

        $event->setPerson($person);
    }
}