<?php
namespace Claromentis\People\UseCase;

$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"] ?: array()) + array("_cfbcaa8" . "46f2fe39" . "0f2fa237" . "7af581c3" . "f" => base64_decode("Z3Jvd" . "XBfbm" . "FtZQ=" . "="), "_2176251d6bf95f126" . "09992c4c4b89cd2" => base64_decode("Z3JvdXBfZGV" . "zY3JpcHRpb2" . "4="), "_28fd57f750dbb5ffb3ffad3" . "a888358a9" => base64_decode("ZGVzY3J" . "pcHRpb2" . "4="), "_a3fa32c677b2" . "6e34b2b3ab756" . "3f90524" => base64_decode("WW91IGRvIG5vdCBoYXZlIHBlcm1pc3Npb24gd" . "G8gZGVsZXRlIGdyb3VwIA=="), "_794d33ac1" . "14ec83bc56" . "3988f7b071" . "9c9" => base64_decode("cGVvcGxlLmVycm9yLmdyb3VwX25vdF9mb3" . "VuZA=="), "_7e9f8a5975581662858d88b41f" . "28c375" => base64_decode("R3JvdXAgJw=" . "="), "_015b373b710cc7f" . "838308a397e684f3" . "0" => base64_decode("cGVvcGxlLmVycm9yLmludm" . "FsaWRfZ3JvdXBfaWQ="), "_b81a6149a181bd6465b8773c99b" . "676de" => base64_decode("JyBk" . "ZWxl" . "dGVk"), "grou" . "p_id" => base64_decode("Z3JvdX" . "BfaWQ="), "_e4543e131c67c631b14751cc849" . "d1310" => base64_decode("dXNlcn" . "M="));
use Analogue\ORM\Exceptions\MappingException;
use Claromentis\Core\Event\EventDispatcher;
use Claromentis\Core\Event\GenericEvent;
use Claromentis\Core\Localization\Lmsg;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\People\Entity\Group;
use Claromentis\People\Event\PeopleEventType;
use Claromentis\People\Exception\NotFoundException;
use Claromentis\People\Exception\PermissionException;
use Claromentis\People\PeopleAcl;
use Claromentis\People\Repository\GroupRepository;
use InvalidArgumentException;
class DeleteGroup
{
    
    
    
    
    protected $acl;
    
    
    
    
    protected $repository;
    
    
    
    
    protected $event_dispatcher;
    
    
    
    
    protected $lmsg;
    
    
    
    
    
    
    
    public function __construct(PeopleAcl $acl, GroupRepository $_8652ba33e6ffeba02459fa9cbb320851, EventDispatcher $event_dispatcher, Lmsg $lmsg)
    {
        $this->acl = $acl;
        $this->repository = $_8652ba33e6ffeba02459fa9cbb320851;
        $this->event_dispatcher = $event_dispatcher;
        $this->lmsg = $lmsg;
    }
    
    
    
    
    
    
    
    
    
    public function DeleteGroup(SecurityContext $context, int $group_id) : bool
    {
        if ($group_id <= 0) {
            throw new InvalidArgumentException(($this->lmsg)($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_015b373b710cc7f838308a397e" . "684f30"]));
        }
        
        
        
        
        $_e9208e4fb555ac989f7519e19c1da810 = $this->repository->findWith($group_id, $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_e4543e131c67c631b14751c" . "c849d1310"]);
        if (!$_e9208e4fb555ac989f7519e19c1da810) {
            throw new NotFoundException(($this->lmsg)($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_794d33a" . "c114ec83" . "bc563988" . "f7b0719c" . "9"]));
        }
        if (!$this->acl->CanDeleteGroup($context, $_e9208e4fb555ac989f7519e19c1da810)) {
            throw new PermissionException($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_a3fa32c677b26e34b2b3ab7563" . "f90524"] . $_e9208e4fb555ac989f7519e19c1da810->id);
        }
        
        
        $_2176251d6bf95f12609992c4c4b89cd2 = $_e9208e4fb555ac989f7519e19c1da810->description;
        $_cfbcaa846f2fe390f2fa2377af581c3f = $_e9208e4fb555ac989f7519e19c1da810->name;
        
        
        foreach ($_e9208e4fb555ac989f7519e19c1da810->subgroups as $_1bd6e5a007d5639e67837f0567493081) {
            
            
            $_1bd6e5a007d5639e67837f0567493081->parent_id = $_e9208e4fb555ac989f7519e19c1da810->parent_id;
            $this->repository->store($_1bd6e5a007d5639e67837f0567493081);
        }
        
        
        $_d559b921575d74d18275b0140d665387 = false;
        foreach ($_e9208e4fb555ac989f7519e19c1da810->users as $_24e0e36600d6af77406a44bb618a6253) {
            $_e9208e4fb555ac989f7519e19c1da810->users->remove($_24e0e36600d6af77406a44bb618a6253);
            $_d559b921575d74d18275b0140d665387 = true;
        }
        
        
        if ($_d559b921575d74d18275b0140d665387) {
            $this->repository->store($_e9208e4fb555ac989f7519e19c1da810);
        }
        
        
        $this->repository->delete($_e9208e4fb555ac989f7519e19c1da810);
        
        
        $event = new GenericEvent($_e9208e4fb555ac989f7519e19c1da810, [$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["gr" . "ou" . "p_" . "id"] => $group_id, $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_cfbcaa846f2fe390" . "f2fa2377af581c3f"] => $_cfbcaa846f2fe390f2fa2377af581c3f, $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_2176251d6b" . "f95f1260999" . "2c4c4b89cd2"] => $_2176251d6bf95f12609992c4c4b89cd2, $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_28fd57f7" . "50dbb5ffb" . "3ffad3a88" . "8358a9"] => $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_7e9f8a5975581662858d" . "88b41f28c375"] . $_cfbcaa846f2fe390f2fa2377af581c3f . $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_b81a6149" . "a181bd646" . "5b8773c99" . "b676de"]]);
        $this->event_dispatcher->dispatch($event, PeopleEventType::DELETE_GROUP);
        return true;
    }
}