<?php
namespace Claromentis\People\UseCase;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"] ?: array()) + array("_6c8c5387f046854f266c918d1562" . "fe23" => base64_decode("cGVvcGxlLmVycm9yL" . "mV4dHJhbmV0X3ByaW" . "1hcnlfZm9yYmlkZGV" . "u"), "_40e4f9acaf" . "edcbde90d63" . "a6cf690bfa6" => base64_decode("WW91IGRvIG5vdCBoYXZlIHBlcm1pc" . "3Npb24gdG8gY3JlYXRlIGV4dHJhbm" . "V0cw=="), "_28a01c8" . "e8c6cb66" . "5cc83d03" . "df4a6977" . "b" => base64_decode("YWRtaW" . "5faWQ="));
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 CreateExtranet
{
    
    
    
    
    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 CreateExtranet(SecurityContext $context, array $_809a58dc73011173c031a53c0b40ef0e)
    {
        if (!$this->acl->CanCreateExtranet($context)) {
            throw new PermissionException($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_40e4f9ac" . "afedcbde9" . "0d63a6cf6" . "90bfa6"]);
        }
        
        
        if (!isset($_809a58dc73011173c031a53c0b40ef0e[$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_28a01c8" . "e8c6cb66" . "5cc83d03" . "df4a6977" . "b"]])) {
            $_809a58dc73011173c031a53c0b40ef0e[$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_28a01c8e8c6cb665cc83d03d" . "f4a6977b"]] = $context->GetUserId();
        }
        $_809a58dc73011173c031a53c0b40ef0e = $this->validator->Validate(null, $_809a58dc73011173c031a53c0b40ef0e);
        
        
        $_9a2ef4ae6a5745ffe5fac33c88a222fa = $this->repo->newInstance();
        $_9a2ef4ae6a5745ffe5fac33c88a222fa->fill($_809a58dc73011173c031a53c0b40ef0e);
        if ($_9a2ef4ae6a5745ffe5fac33c88a222fa->isPrimary() && !$this->acl->IsPeopleAdmin($context)) {
            throw new PermissionException(($this->lmsg)($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_6c8c5387f046854f266c91" . "8d1562fe23"]));
        }
        $_9a2ef4ae6a5745ffe5fac33c88a222fa = $this->repo->store($_9a2ef4ae6a5745ffe5fac33c88a222fa);
        if ($_9a2ef4ae6a5745ffe5fac33c88a222fa->isPrimary()) {
            $this->set_primary_extranet->SetPrimaryExtranet($context, $_9a2ef4ae6a5745ffe5fac33c88a222fa->id);
        }
        $event = new GenericEvent($_9a2ef4ae6a5745ffe5fac33c88a222fa);
        $this->dispatcher->dispatch(PeopleEventType::ADD_EXTRANET, $event);
        return $_9a2ef4ae6a5745ffe5fac33c88a222fa;
    }
}