<?php
namespace Claromentis\People\UseCase;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"] ?: array()) + array("_015b373b710cc7f838308a39" . "7e684f30" => base64_decode("cGVvcGxlLmVycm9yLm" . "ludmFsaWRfZ3JvdXBf" . "aWQ="), "_e4543e131c67c631b1" . "4751cc849d1310" => base64_decode("dXNl" . "cnM="), "_b81a6149a" . "181bd6465b" . "8773c99b67" . "6de" => base64_decode("JyB" . "kZW" . "xld" . "GVk"), "_2176251d6bf95f126099" . "92c4c4b89cd2" => base64_decode("Z3JvdXBf" . "ZGVzY3Jp" . "cHRpb24="), "_7e9f8a597" . "5581662858" . "d88b41f28c" . "375" => base64_decode("R3J" . "vdX" . "AgJ" . "w=="), "_a3fa32c677b26e" . "34b2b3ab7563f90" . "524" => base64_decode("WW91IGRvIG5vdCBoYXZlIHBlcm1pc3Npb24gdG8gZGVsZXRlIGd" . "yb3VwIA=="), "gro" . "up_" . "id" => base64_decode("Z3Jvd" . "XBfaW" . "Q="), "_28fd57f750dbb5ffb3ffad3a888358a" . "9" => base64_decode("ZGVz" . "Y3Jp" . "cHRp" . "b24="), "_794d33ac114ec83bc5" . "63988f7b0719c9" => base64_decode("cGVvcGxlLmVycm9yLmdyb3VwX2" . "5vdF9mb3VuZA=="));
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["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_015b373b71" . "0cc7f838308" . "a397e684f30"]));
        }
        
        
        
        
        $_e9208e4fb555ac989f7519e19c1da810 = $this->repository->findWith($group_id, $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_e4543e131c67c631b14751cc849d13" . "10"]);
        if (!$_e9208e4fb555ac989f7519e19c1da810) {
            throw new NotFoundException(($this->lmsg)($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_794d33ac114ec" . "83bc563988f7b0" . "719c9"]));
        }
        if (!$this->acl->CanDeleteGroup($context, $_e9208e4fb555ac989f7519e19c1da810)) {
            throw new PermissionException($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_a3fa32c677" . "b26e34b2b3a" . "b7563f90524"] . $_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["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["gro" . "up_" . "id"] => $group_id, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_2176251d6bf95f12609992c4c4b89" . "cd2"] => $_2176251d6bf95f12609992c4c4b89cd2, $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_28fd57f750dbb5ffb3ffad3a88835" . "8a9"] => $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_7e9f8a5975581662858d88b" . "41f28c375"] . $_cfbcaa846f2fe390f2fa2377af581c3f . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_b81a6149a181bd6465b" . "8773c99b676de"]]);
        $this->event_dispatcher->dispatch(PeopleEventType::DELETE_GROUP, $event);
        return true;
    }
}