<?php
namespace Claromentis\People\UseCase;

$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"] ?: array()) + array("_99c0ce54678bc626deadaf7cc634f" . "a8b" => base64_decode("cGVvcGxlLmVycm9yLmV4dHJhbmV0X2Nhbm5vdF9yZ" . "W1vdmVfcHJpbWFyeQ=="), "_a1009d9c49c875d5b2778d652e37d" . "301" => base64_decode("b2x" . "kX2" . "Rhd" . "GE="), "_77fa83c392cb76a99d64e" . "53cd6d52a90" => base64_decode("WW91IGRvIG5vdCBoYXZlIHBlcm1pc3Npb24gdG8gdXBkYXRlIHRoaXMg" . "RXh0cmFuZXQ="), "_6c8c538" . "7f046854" . "f266c918" . "d1562fe2" . "3" => base64_decode("cGVvcGxlLmVycm9yLmV4dHJ" . "hbmV0X3ByaW1hcnlfZm9yYm" . "lkZGVu"));
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\Extranet;
use Claromentis\People\Event\PeopleEventType;
use Claromentis\People\Exception\NotFoundException;
use Claromentis\People\Exception\PermissionException;
use Claromentis\People\PeopleAcl;
use Claromentis\People\Repository\ExtranetRepository;
use Claromentis\People\Exception\ValidationException;
use Claromentis\People\Validator\ExtranetValidator;
class UpdateExtranet
{
    
    
    
    
    private $acl;
    
    
    
    
    private $lmsg;
    
    
    
    
    private $repo;
    
    
    
    
    private $validator;
    
    
    
    
    private $dispatcher;
    
    
    
    
    private $set_primary_extranet;
    public function __construct(PeopleAcl $acl, Lmsg $lmsg, ExtranetRepository $repo, ExtranetValidator $_24c8d051c033d19c2c97cdc3d7098b1b, EventDispatcher $dispatcher, SetPrimaryExtranet $_48cffa64618aed4674a24bcf2f374138)
    {
        $this->acl = $acl;
        $this->lmsg = $lmsg;
        $this->repo = $repo;
        $this->validator = $_24c8d051c033d19c2c97cdc3d7098b1b;
        $this->dispatcher = $dispatcher;
        $this->set_primary_extranet = $_48cffa64618aed4674a24bcf2f374138;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function UpdateExtranet(SecurityContext $context, int $extranet_id, array $_809a58dc73011173c031a53c0b40ef0e) : Extranet
    {
        if (!$this->acl->CanUpdateExtranet($context, $extranet_id)) {
            throw new PermissionException($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_77fa83c392cb76a99d64" . "e53cd6d52a90"]);
        }
        $_809a58dc73011173c031a53c0b40ef0e = $this->validator->Validate($extranet_id, $_809a58dc73011173c031a53c0b40ef0e);
        
        
        $_9a2ef4ae6a5745ffe5fac33c88a222fa = $this->repo->find($extranet_id);
        $_01a87ab6d900a7d3584ae7951b164797 = $_9a2ef4ae6a5745ffe5fac33c88a222fa->isPrimary();
        $_a1009d9c49c875d5b2778d652e37d301 = $_9a2ef4ae6a5745ffe5fac33c88a222fa->toArray();
        $_9a2ef4ae6a5745ffe5fac33c88a222fa->fill($_809a58dc73011173c031a53c0b40ef0e);
        $_82cec26ce0569cdb00c81908901b8f5e = $_9a2ef4ae6a5745ffe5fac33c88a222fa->isPrimary();
        if ($_01a87ab6d900a7d3584ae7951b164797 !== $_82cec26ce0569cdb00c81908901b8f5e && !$this->acl->IsPeopleAdmin($context)) {
            throw new PermissionException(($this->lmsg)($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_6c8c5387f046854f266c918" . "d1562fe23"]));
        }
        if ($_01a87ab6d900a7d3584ae7951b164797 && !$_82cec26ce0569cdb00c81908901b8f5e) {
            throw new ValidationException(($this->lmsg)($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_99c0ce5467" . "8bc626deada" . "f7cc634fa8b"]));
        }
        $_9a2ef4ae6a5745ffe5fac33c88a222fa = $this->repo->store($_9a2ef4ae6a5745ffe5fac33c88a222fa);
        if ($_9a2ef4ae6a5745ffe5fac33c88a222fa->isPrimary()) {
            $this->set_primary_extranet->SetPrimaryExtranet($context, $_9a2ef4ae6a5745ffe5fac33c88a222fa->id);
        }
        $event = new GenericEvent($_9a2ef4ae6a5745ffe5fac33c88a222fa, [$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_a1009d9c49c875d5b277" . "8d652e37d301"] => $_a1009d9c49c875d5b2778d652e37d301]);
        $this->dispatcher->dispatch(PeopleEventType::UPDATE_EXTRANET, $event);
        return $_9a2ef4ae6a5745ffe5fac33c88a222fa;
    }
}