<?php
namespace Claromentis\People\UseCase;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"] ?: array()) + array("_2176251d6bf95f12609992c4c4b8" . "9cd2" => base64_decode("Z3JvdXBfZGVzY3JpcHRpb2" . "4="), "_7309594781df221c77392" . "6c720238ef8" => base64_decode("ZnVsbG5hbW" . "U="), "_fd30c6ba90c4504141c79c70d958" . "009e" => base64_decode("VXNlcnMgbm90IGZvdW5kO" . "iA="), "_563ff810" . "a52884f61" . "66f526dc2" . "866582" => base64_decode("IHdhcyBzZXQgZm9y" . "IHVzZXJzIA=="), "_28fd57f750dbb5ffb3ffad3a88835" . "8a9" => base64_decode("ZGVzY3JpcHRpb24" . "="), "_0ec78c9f2bc193746cc8fe9" . "eba6b2e3b" => base64_decode("R3Jv" . "dXAg"), "_26cdbc145b3a6473db7fdcee042146" . "4d" => base64_decode("IGNhbm5vdCBiZSBhc3NpZ25lZCB0byB" . "ncm91cCA="), "_01f117db67aa74" . "9d3ec8da7eb4787" . "30c" => base64_decode("L" . "C" . "A" . "="), "_b66252d7bbf361012a6531a8e3a7" . "3230" => base64_decode("YXJyYXlfZGl" . "mZg=="), "_aa01344e9bf0e5480edbbcd115" . "2e335e" => base64_decode("QXNzaWdubWV" . "udCBwZXJtaX" . "NzaW9uIGVyc" . "m9ycw=="), "_2e814283e7dc" . "09e1bffbc2ae9" . "e6752b5" => base64_decode("WW91IGRvIG5vdCBoYXZlIHBlc" . "m1pc3Npb24gdG8gdXBkYXRlIH" . "VzZXIg"), "_5159b3572969eca46acd1b2e14" . "18459c" => base64_decode("aW1wbG" . "9kZQ=="), "_cfbcaa8" . "46f2fe39" . "0f2fa237" . "7af581c3" . "f" => base64_decode("Z3JvdXBf" . "bmFtZQ=="), "_1ac5cc48c34c5362e94d8667cc7" . "b0ddc" => base64_decode("LA" . "=="), "gr" . "ou" . "p_" . "id" => base64_decode("Z3JvdXBfaWQ" . "="), "_794d33ac114ec83bc5639" . "88f7b0719c9" => base64_decode("cGVvcGxlLmVycm9yLmdyb3VwX2" . "5vdF9mb3VuZA=="), "_7331abbad24fbe" . "11818f3e4e93674" . "4ce" => base64_decode("WW91IGRvIG5vdCBoYXZlI" . "HBlcm1pc3Npb24gdG8gYX" . "NzaWduIHVzZXJzIHRvIGd" . "yb3VwIA=="), "_9d799ff313bcf1dd5c17f004da40f2" . "31" => base64_decode("VXNlciA" . "="));
use Analogue\ORM\EntityCollection;
use Analogue\ORM\Exceptions\MappingException;
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\Exception\ValidationException;
use Claromentis\People\PeopleAcl;
use Claromentis\People\Repository\GroupRepository;
use Claromentis\People\Repository\UserRepository;
use Claromentis\People\Validator\Util;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class SetGroupUsers
{
    
    
    
    
    protected $acl;
    
    
    
    
    protected $lmsg;
    
    
    
    
    protected $group_repository;
    
    
    
    
    protected $user_repository;
    
    
    
    
    protected $dispatcher;
    
    
    
    
    
    
    
    
    
    
    public function __construct(PeopleAcl $acl, Lmsg $lmsg, GroupRepository $_efe123fd19d21a3a78376b566dad7284, UserRepository $_eeeeb0d673b7b0fd0bdca58b5541c3e0, EventDispatcherInterface $dispatcher)
    {
        $this->acl = $acl;
        $this->lmsg = $lmsg;
        $this->group_repository = $_efe123fd19d21a3a78376b566dad7284;
        $this->user_repository = $_eeeeb0d673b7b0fd0bdca58b5541c3e0;
        $this->dispatcher = $dispatcher;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function SetGroupUsers(SecurityContext $context, int $group_id, array $_17247f55ce15f647f57c3ef8bb3a474a) : EntityCollection
    {
        
        
        
        
        $_e9208e4fb555ac989f7519e19c1da810 = $this->group_repository->find($group_id);
        if (!$_e9208e4fb555ac989f7519e19c1da810) {
            throw new NotFoundException(($this->lmsg)($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_794d33ac114e" . "c83bc563988f7" . "b0719c9"]));
        }
        if (!$this->acl->CanAssignGroupUsers($context, $_e9208e4fb555ac989f7519e19c1da810)) {
            throw new PermissionException($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_7331abbad24fbe11818f3e" . "4e936744ce"] . $_e9208e4fb555ac989f7519e19c1da810->id);
        }
        Util::ValidateIds($_17247f55ce15f647f57c3ef8bb3a474a);
        $_e4543e131c67c631b14751cc849d1310 = $this->user_repository->find($_17247f55ce15f647f57c3ef8bb3a474a);
        $this->ValidateAssignment($context, $_17247f55ce15f647f57c3ef8bb3a474a, $_e4543e131c67c631b14751cc849d1310, $_e9208e4fb555ac989f7519e19c1da810);
        $_e9208e4fb555ac989f7519e19c1da810->users = null;
        $this->group_repository->store($_e9208e4fb555ac989f7519e19c1da810);
        $_e9208e4fb555ac989f7519e19c1da810->users = $_e4543e131c67c631b14751cc849d1310;
        $this->group_repository->store($_e9208e4fb555ac989f7519e19c1da810);
        $_8c275ff377eb67770c4e2dbb865f06a3 = $_e4543e131c67c631b14751cc849d1310->implode($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_7309594781df22" . "1c773926c720238" . "ef8"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_1ac5cc48c34c5362e94d8667cc7b" . "0ddc"]);
        $event = new GenericEvent($_e9208e4fb555ac989f7519e19c1da810, [$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["group" . "_id"] => $group_id, $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_cfbcaa846f2fe390f2fa2377af" . "581c3f"] => $_e9208e4fb555ac989f7519e19c1da810->name, $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_2176251d6bf95f12609992c" . "4c4b89cd2"] => $_e9208e4fb555ac989f7519e19c1da810->description, $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_28fd57f750dbb5ffb3ffad3a8883" . "58a9"] => $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_0ec78c9f2b" . "c193746cc8f" . "e9eba6b2e3b"] . $_e9208e4fb555ac989f7519e19c1da810->name . $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_563ff81" . "0a52884f" . "6166f526" . "dc286658" . "2"] . $_8c275ff377eb67770c4e2dbb865f06a3]);
        $this->dispatcher->dispatch(PeopleEventType::SET_GROUP_USERS, $event);
        return $_e4543e131c67c631b14751cc849d1310;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    protected function ValidateAssignment(SecurityContext $context, array $_17247f55ce15f647f57c3ef8bb3a474a, EntityCollection $_e4543e131c67c631b14751cc849d1310, Group $_e9208e4fb555ac989f7519e19c1da810)
    {
        
        
        $_7c1e05edb74be7af2a2c97d5853fac62 = $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_b66252d7bbf361012a6531a8e3a73" . "230"]($_17247f55ce15f647f57c3ef8bb3a474a, $_e4543e131c67c631b14751cc849d1310->getEntityKeys());
        if ($_7c1e05edb74be7af2a2c97d5853fac62) {
            throw new ValidationException($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_fd30c6ba90c4504141c79c70d9580" . "09e"] . $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_5159b3572969eca46acd1b" . "2e1418459c"]($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_01f117db6" . "7aa749d3ec" . "8da7eb4787" . "30c"], $_7c1e05edb74be7af2a2c97d5853fac62));
        }
        
        
        $_c78f29e7b113c7a4d29fe3c4468181e9 = [];
        foreach ($_e4543e131c67c631b14751cc849d1310 as $_24e0e36600d6af77406a44bb618a6253) {
            $_ac28a0119009e23ea788d6c83912cde1 = SecurityContext::CreateForUser($_24e0e36600d6af77406a44bb618a6253->id);
            if (!$this->acl->CanUpdateUser($context, $_24e0e36600d6af77406a44bb618a6253)) {
                $_c78f29e7b113c7a4d29fe3c4468181e9[] = $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_2e814283e7dc09e1bf" . "fbc2ae9e6752b5"] . $_24e0e36600d6af77406a44bb618a6253->id;
            } elseif (!$this->acl->CanBelongToGroup($_ac28a0119009e23ea788d6c83912cde1, $_e9208e4fb555ac989f7519e19c1da810)) {
                $_c78f29e7b113c7a4d29fe3c4468181e9[] = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_9d799ff313bcf1dd5c" . "17f004da40f231"] . $_24e0e36600d6af77406a44bb618a6253->id . $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_26cdbc145b3a647" . "3db7fdcee0421464" . "d"] . $_e9208e4fb555ac989f7519e19c1da810->id;
            }
        }
        if (!empty($_c78f29e7b113c7a4d29fe3c4468181e9)) {
            throw (new PermissionException($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_aa01344e9bf0e5480edbbcd11" . "52e335e"]))->setErrors($_c78f29e7b113c7a4d29fe3c4468181e9);
        }
    }
}