<?php
namespace Claromentis\People\UseCase;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"] = (@$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"] ?: array()) + array("_94c782c81" . "80766e1ff1" . "870975a930" . "53d" => base64_decode("Um9sZSBub3QgZm91bm" . "Q="), "_64c9177a48c5" . "1e010a72189a0" . "3443a3d" => base64_decode("Um9sZ" . "SAn"), "_50de2c5f46" . "1bce4b2f793" . "c1981a022b8" => base64_decode("cm9sZV9kZX" . "NjcmlwdGlv" . "bg=="), "_e60476ae65c799c" . "d72d6db8a5c5e35f" . "e" => base64_decode("WW91IGRvIG5vdCBoYXZlIHBlcm1pc3Npb24" . "gdG8gZGVsZXRlIHRoaXMgcm9sZQ=="), "_28fd57f750dbb" . "5ffb3ffad3a888" . "358a9" => base64_decode("ZGVz" . "Y3Jp" . "cHRp" . "b24="), "_b81a6149a181bd6465b8773c99b" . "676de" => base64_decode("JyBkZWxl" . "dGVk"), "role_" . "id" => base64_decode("cm9sZV9pZA" . "=="));
use Analogue\ORM\Exceptions\MappingException;
use Claromentis\Core\Event\GenericEvent;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\People\Entity\Role;
use Claromentis\People\Event\PeopleEventType;
use Claromentis\People\Exception\NotFoundException;
use Claromentis\People\Exception\PermissionException;
use Claromentis\People\PeopleAcl;
use Claromentis\People\Repository\RoleRepository;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class DeleteRole
{
    
    
    
    
    protected $acl;
    
    
    
    
    protected $repository;
    
    
    
    
    protected $dispatcher;
    
    
    
    
    
    
    public function __construct(PeopleAcl $acl, RoleRepository $repository, EventDispatcherInterface $dispatcher)
    {
        $this->acl = $acl;
        $this->repository = $repository;
        $this->dispatcher = $dispatcher;
    }
    
    
    
    
    
    
    
    
    
    public function DeleteRole(SecurityContext $context, int $role_id)
    {
        
        
        
        
        
        
        $_d1071a032215f0eb5c4a8ef175f7049d = $this->repository->find($role_id);
        if (!$_d1071a032215f0eb5c4a8ef175f7049d) {
            throw new NotFoundException($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_94c782c8180" . "766e1ff18709" . "75a93053d"]);
        }
        if (!$this->acl->CanDeleteRole($context, $_d1071a032215f0eb5c4a8ef175f7049d)) {
            throw new PermissionException($GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_e60476ae65c799cd72d6" . "db8a5c5e35fe"]);
        }
        
        
        $this->repository->delete($_d1071a032215f0eb5c4a8ef175f7049d);
        
        
        $event = new GenericEvent($_d1071a032215f0eb5c4a8ef175f7049d, [$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["role" . "_id"] => $_d1071a032215f0eb5c4a8ef175f7049d->id, $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_50de2c5f461bce4b2f" . "793c1981a022b8"] => $_d1071a032215f0eb5c4a8ef175f7049d->description, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_28fd57f750dbb5ffb3ffad3" . "a888358a9"] => $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_64c9177a48c51e010a721" . "89a03443a3d"] . $_d1071a032215f0eb5c4a8ef175f7049d->name . $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_b81a6149a181bd646" . "5b8773c99b676de"]]);
        $this->dispatcher->dispatch($event, PeopleEventType::DELETE_ROLE);
        return $_d1071a032215f0eb5c4a8ef175f7049d->id;
    }
}