<?php
namespace Claromentis\People\UseCase;

$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"] = (@$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"] ?: array()) + array("_31767d7ad58e706dbf47b7a51a0fe6" . "c4" => base64_decode("Y2" . "91" . "bn" . "Q="), "_14d6f569" . "37cb3c3af" . "7f12322a8" . "047432" => base64_decode("KSBvciBncm91cH" . "MgKA=="), "_7ea0db3a0270b38" . "917803d1824858ee" . "0" => base64_decode("KSBhc3NpZ25lZCB0" . "byB5b3VyIGV4dHJh" . "bmV0Lg=="), "_ca8f486e67f34fef19f90a3fbe4" . "2a5f9" => base64_decode("KSwgcm9sZXM" . "gKA=="), "_9037e6aff0f02d0d332070f8b6d5e4c" . "a" => base64_decode("WW91IGh" . "hdmUgdX" . "NlcnMgK" . "A=="), "_24e0e36600d6af77406a44bb618a6" . "253" => base64_decode("dXNlcg" . "=="), "_86f42e271884da3dd0a0eae5e" . "2a8e382" => base64_decode("Tm8gcGVybWlzc2lvbiB0byBkZWxldGUgZXh0cmFuZXQgS" . "UQg"), "_8837db10b233d6be2bdf" . "b1969660d91d" => base64_decode("YXJyYXlf" . "c3Vt"), "_d1071a032215f0eb5c4a8e" . "f175f7049d" => base64_decode("cm9s" . "ZQ=="), "_e9208e4fb555a" . "c989f7519e19c1" . "da810" => base64_decode("Z3Jvd" . "XA="));
use Analogue\ORM\Exceptions\MappingException;
use Claromentis\Core\Event\EventDispatcher;
use Claromentis\Core\Event\GenericEvent;
use Claromentis\Core\Security\Exception\AccessDeniedException;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\People\Entity\Extranet;
use Claromentis\People\Event\PeopleEventType;
use Claromentis\People\PeopleAcl;
use Claromentis\People\Repository\ExtranetRepository;
use Claromentis\People\Exception\ValidationException;
use Claromentis\People\Validator\ExtranetValidator;
class DeleteExtranet
{
    
    
    
    
    protected $acl;
    
    
    
    
    protected $dispatcher;
    
    
    private $repo;
    
    
    private $validator;
    public function __construct(ExtranetRepository $repo, ExtranetValidator $_24c8d051c033d19c2c97cdc3d7098b1b, PeopleAcl $acl, EventDispatcher $dispatcher)
    {
        $this->repo = $repo;
        $this->validator = $_24c8d051c033d19c2c97cdc3d7098b1b;
        $this->acl = $acl;
        $this->dispatcher = $dispatcher;
    }
    
    
    
    
    
    
    
    
    
    
    
    public function delete(SecurityContext $context, $extranet_id, $_921fbf4c866dff55f6a4cab0c7be03ff = null)
    {
        if (!$this->acl->CanDeleteExtranet($context, $extranet_id)) {
            throw new AccessDeniedException($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_86f42e27" . "1884da3dd" . "0a0eae5e2" . "a8e382"] . $extranet_id);
        }
        $this->validator->ValidateDelete($extranet_id, $_921fbf4c866dff55f6a4cab0c7be03ff);
        
        
        $_9a2ef4ae6a5745ffe5fac33c88a222fa = $this->repo->find($extranet_id);
        $_f53d35a1a1e233d98d9ce73d92ab3bb1 = [];
        $_f53d35a1a1e233d98d9ce73d92ab3bb1[$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_24e0e36600d6af774" . "06a44bb618a6253"]] = $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_31767d7ad" . "58e706dbf4" . "7b7a51a0fe" . "6c4"]($_9a2ef4ae6a5745ffe5fac33c88a222fa->users);
        $_f53d35a1a1e233d98d9ce73d92ab3bb1[$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_d1071a032" . "215f0eb5c4" . "a8ef175f70" . "49d"]] = $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_31767d7a" . "d58e706db" . "f47b7a51a" . "0fe6c4"]($_9a2ef4ae6a5745ffe5fac33c88a222fa->roles);
        $_f53d35a1a1e233d98d9ce73d92ab3bb1[$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_e9208e4f" . "b555ac989" . "f7519e19c" . "1da810"]] = $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_31767d7ad58e706dbf4" . "7b7a51a0fe6c4"]($_9a2ef4ae6a5745ffe5fac33c88a222fa->groups);
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_8837db10b233d6be2bdfb1" . "969660d91d"]($_f53d35a1a1e233d98d9ce73d92ab3bb1) > 0) {
            if ($_921fbf4c866dff55f6a4cab0c7be03ff) {
                $this->ReassignEntities($_9a2ef4ae6a5745ffe5fac33c88a222fa, $_921fbf4c866dff55f6a4cab0c7be03ff);
            } else {
                throw new ValidationException($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_9037e6aff0f0" . "2d0d332070f8b" . "6d5e4ca"] . $_f53d35a1a1e233d98d9ce73d92ab3bb1[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_24e0e36600d6" . "af77406a44bb6" . "18a6253"]] . $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_ca8f486e67f34fef" . "19f90a3fbe42a5f9"] . $_f53d35a1a1e233d98d9ce73d92ab3bb1[$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_d1071a03221" . "5f0eb5c4a8ef" . "175f7049d"]] . $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_14d6f56937cb3c3af7f123" . "22a8047432"] . $_f53d35a1a1e233d98d9ce73d92ab3bb1[$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_e9208e4fb555ac989" . "f7519e19c1da810"]] . $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_7ea0db3a02" . "70b38917803" . "d1824858ee0"]);
            }
        }
        $event = new GenericEvent($_9a2ef4ae6a5745ffe5fac33c88a222fa);
        $this->dispatcher->dispatch(PeopleEventType::DELETE_EXTRANET, $event);
        $this->repo->delete($_9a2ef4ae6a5745ffe5fac33c88a222fa);
    }
    
    
    
    
    
    
    protected function ReassignEntities(Extranet $_9a2ef4ae6a5745ffe5fac33c88a222fa, int $_414d049a510f8b42a336b7e7f830343e)
    {
        foreach ($_9a2ef4ae6a5745ffe5fac33c88a222fa->users as $_24e0e36600d6af77406a44bb618a6253) {
            $_24e0e36600d6af77406a44bb618a6253->extranet_id = $_414d049a510f8b42a336b7e7f830343e;
        }
        foreach ($_9a2ef4ae6a5745ffe5fac33c88a222fa->roles as $_d1071a032215f0eb5c4a8ef175f7049d) {
            $_d1071a032215f0eb5c4a8ef175f7049d->extranet_id = $_414d049a510f8b42a336b7e7f830343e;
        }
        foreach ($_9a2ef4ae6a5745ffe5fac33c88a222fa->groups as $_e9208e4fb555ac989f7519e19c1da810) {
            $_e9208e4fb555ac989f7519e19c1da810->extranet_id = $_414d049a510f8b42a336b7e7f830343e;
        }
        $this->repo->store($_9a2ef4ae6a5745ffe5fac33c88a222fa);
    }
}