<?php
namespace Claromentis\People\UseCase;

$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"] ?: array()) + array("gro" . "up_" . "id" => base64_decode("Z3J" . "vdX" . "Bfa" . "WQ="), "_9d799ff313bcf1dd5c17f004da40f2" . "31" => base64_decode("VX" . "Nl" . "ci" . "A="), "_2176251d" . "6bf95f126" . "09992c4c4" . "b89cd2" => base64_decode("Z3JvdXBfZGVzY3JpcH" . "Rpb24="), "_2e814283e7d" . "c09e1bffbc2a" . "e9e6752b5" => base64_decode("WW91IGRvIG5vdCBoYXZlIHBlcm" . "1pc3Npb24gdG8gdXBkYXRlIHVz" . "ZXIg"), "_cfbcaa846f2fe390f2fa23" . "77af581c3f" => base64_decode("Z3JvdXBfbmFt" . "ZQ=="), "_fd30c6ba90c4504" . "141c79c70d958009" . "e" => base64_decode("VXNlcnMgbm90IGZvdW5kO" . "iA="), "_0ec78c9f2bc193746cc8" . "fe9eba6b2e3b" => base64_decode("R3Jvd" . "XAg"), "_794d33ac114ec83bc563988f" . "7b0719c9" => base64_decode("cGVvcGxlLmVycm9yLmdy" . "b3VwX25vdF9mb3VuZA=="), "_28fd57f75" . "0dbb5ffb3f" . "fad3a88835" . "8a9" => base64_decode("ZGVzY3Jpc" . "HRpb24="), "_7309594781df221c773926c720238" . "ef8" => base64_decode("ZnVsbG5h" . "bWU="), "_5159b3572969ec" . "a46acd1b2e14184" . "59c" => base64_decode("aW1" . "wbG" . "9kZ" . "Q=="), "_563ff810a52884f6166f526dc" . "2866582" => base64_decode("IHdhcyBzZXQgZm9yIHVzZXJ" . "zIA=="), "_1ac5cc48" . "c34c5362e" . "94d8667cc" . "7b0ddc" => base64_decode("L" . "A" . "=" . "="), "_aa01344e9bf0e5480edbbcd1152" . "e335e" => base64_decode("QXNzaWdubWVudCBwZXJtaXN" . "zaW9uIGVycm9ycw=="), "_7331abbad24fbe11818f3e4e936" . "744ce" => base64_decode("WW91IGRvIG5vdCBoYXZlIHBlcm1pc3Npb24gdG8gY" . "XNzaWduIHVzZXJzIHRvIGdyb3VwIA=="), "_b66252d7bb" . "f361012a653" . "1a8e3a73230" => base64_decode("YXJyYXlfZGlmZ" . "g=="), "_01f117db67aa" . "749d3ec8da7eb" . "478730c" => base64_decode("L" . "C" . "A" . "="), "_26cdbc145b3a6473db7fdce" . "e0421464d" => base64_decode("IGNhbm5vdCBiZS" . "Bhc3NpZ25lZCB0" . "byBncm91cCA="));
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["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_794d33ac114ec83bc563988" . "f7b0719c9"]));
        }
        if (!$this->acl->CanAssignGroupUsers($context, $_e9208e4fb555ac989f7519e19c1da810)) {
            throw new PermissionException($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_7331abbad24fbe11818" . "f3e4e936744ce"] . $_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["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_7309594781df221c773926c7202" . "38ef8"], $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_1ac5cc48c34c5362e94d86" . "67cc7b0ddc"]);
        $event = new GenericEvent($_e9208e4fb555ac989f7519e19c1da810, [$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["group_i" . "d"] => $group_id, $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_cfbcaa846f2fe390f2fa237" . "7af581c3f"] => $_e9208e4fb555ac989f7519e19c1da810->name, $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_2176251d6bf95f12609992c4c4b89c" . "d2"] => $_e9208e4fb555ac989f7519e19c1da810->description, $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_28fd57f750dbb5ffb3ffad3" . "a888358a9"] => $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_0ec78c9f2bc1937" . "46cc8fe9eba6b2e3" . "b"] . $_e9208e4fb555ac989f7519e19c1da810->name . $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_563ff810a52884f6166f526d" . "c2866582"] . $_8c275ff377eb67770c4e2dbb865f06a3]);
        $this->dispatcher->dispatch(PeopleEventType::SET_GROUP_USERS, $event);
        return $_e4543e131c67c631b14751cc849d1310;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    protected function ValidateAssignment(SecurityContext $context, array $_17247f55ce15f647f57c3ef8bb3a474a, EntityCollection $_e4543e131c67c631b14751cc849d1310, Group $_e9208e4fb555ac989f7519e19c1da810)
    {
        
        
        $_7c1e05edb74be7af2a2c97d5853fac62 = $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_b66252d7bbf361012a6531a8e3a732" . "30"]($_17247f55ce15f647f57c3ef8bb3a474a, $_e4543e131c67c631b14751cc849d1310->getEntityKeys());
        if ($_7c1e05edb74be7af2a2c97d5853fac62) {
            throw new ValidationException($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_fd30c6ba90c4504141c7" . "9c70d958009e"] . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_5159b3572969eca46acd1b2e141" . "8459c"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_01f117db67aa749d3" . "ec8da7eb478730c"], $_7c1e05edb74be7af2a2c97d5853fac62));
        }
        
        
        $_c78f29e7b113c7a4d29fe3c4468181e9 = [];
        foreach ($_e4543e131c67c631b14751cc849d1310 as $_24e0e36600d6af77406a44bb618a6253) {
            $_ac28a0119009e23ea788d6c83912cde1 = SecurityContext::CreateForUser($_24e0e36600d6af77406a44bb618a6253->id);
            if (!$this->acl->CanUpdateUser($context, $_24e0e36600d6af77406a44bb618a6253)) {
                $_c78f29e7b113c7a4d29fe3c4468181e9[] = $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_2e814283e7dc09e1bf" . "fbc2ae9e6752b5"] . $_24e0e36600d6af77406a44bb618a6253->id;
            } elseif (!$this->acl->CanBelongToGroup($_ac28a0119009e23ea788d6c83912cde1, $_e9208e4fb555ac989f7519e19c1da810)) {
                $_c78f29e7b113c7a4d29fe3c4468181e9[] = $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_9d799ff313bcf1" . "dd5c17f004da40f" . "231"] . $_24e0e36600d6af77406a44bb618a6253->id . $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_26cdbc145b3a6" . "473db7fdcee042" . "1464d"] . $_e9208e4fb555ac989f7519e19c1da810->id;
            }
        }
        if (!empty($_c78f29e7b113c7a4d29fe3c4468181e9)) {
            throw (new PermissionException($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_aa01344e9bf0e5480edbbcd1152e33" . "5e"]))->setErrors($_c78f29e7b113c7a4d29fe3c4468181e9);
        }
    }
}