<?php
namespace Claromentis\People\Controller\Rest;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"] = (@$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"] ?: array()) + array("_aad7e0f9751cf3656148019b0a082" . "88a" => base64_decode("RXh0cmFuZXQgZGVsZ" . "XRlZA=="), "_15f5f162efaff2443798e5cf" . "c813b02b" => base64_decode("Tm9" . "0IG" . "Zvd" . "W5k"), "_7f628626dd1d" . "55c71b1fc0932" . "ffd1d2c" => base64_decode("aXNfYXJy" . "YXk="), "extr" . "anet" . "_id" => base64_decode("ZXh0c" . "mFuZX" . "RfaWQ" . "="), "_3b1fb2e9f34bda" . "2f59863606f440a" . "f60" => base64_decode("QW4gdW5leHBlY3RlZCBlcnJvciBvY2N1" . "cnJlZA=="), "mes" . "sag" . "e" => base64_decode("bWVz" . "c2Fn" . "ZQ=="), "_c894747360" . "c6ec5bd8169" . "530eaf9c473" => base64_decode("QmFk" . "IFJl" . "cXVl" . "c3Q="), "_921fbf4c86" . "6dff55f6a4c" . "ab0c7be03ff" => base64_decode("bmV3X2" . "V4dHJh" . "bmV0X2" . "lk"), "_3efc5ba7bf51ca70907f5" . "e65ab602ec1" => base64_decode("SW50ZXJuYWwgU2VydmVyIEVyc" . "m9y"), "_a4a1018258adabb74e7b048" . "36d8d7e3b" => base64_decode("Tm90IEZvdW5" . "k"), "_79bd87060993ff622ef212c1e8b6a" . "79a" => base64_decode("Rm9yY" . "mlkZG" . "Vu"));
use Analogue\ORM\EntityCollection;
use Analogue\ORM\Exceptions\MappingException;
use Claromentis\Core\CDN\CDNSystemException;
use Claromentis\Core\Http\JsonPrettyResponse;
use Claromentis\Core\Localization\Lmsg;
use Claromentis\Core\Security\Exception\AccessDeniedException;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\People\Exception\NotFoundException;
use Claromentis\People\Exception\PermissionException;
use Claromentis\People\Exception\ValidationException;
use Claromentis\People\Filter\ExtranetFilter;
use Claromentis\People\Filter\UserFilter;
use Claromentis\People\RestFormatter;
use Claromentis\People\UseCase\CreateExtranet;
use Claromentis\People\UseCase\DeleteExtranet;
use Claromentis\People\UseCase\GetExtranet;
use Claromentis\People\UseCase\GetExtranets;
use Claromentis\People\UseCase\GetExtranetUsers;
use Claromentis\People\UseCase\GetPrimaryExtranet;
use Claromentis\People\UseCase\SetExtranetUsers;
use Claromentis\People\UseCase\UpdateExtranet;
use InvalidArgumentException;
use Psr\Http\Message\ServerRequestInterface;
use RestExAuth;
use RestExBadRequest;
use RestExError;
use RestExForbidden;
use RestExNotFound;
class ExtranetController extends AbstractController
{
    
    
    
    
    protected $formatter;
    public function __construct(RestFormatter $format, Lmsg $lmsg)
    {
        $this->formatter = $format;
        $this->lmsg = $lmsg;
    }
    
    
    
    
    
    
    
    
    
    public function GetList(GetExtranets $get_extranets, ServerRequestInterface $request, SecurityContext $context)
    {
        try {
            $_03e9164d0a343b742df4793268b80767 = new ExtranetFilter($context);
            $_03e9164d0a343b742df4793268b80767->Fill($this->formatter->GetRequestParams($request, $_03e9164d0a343b742df4793268b80767->GetDefaults()));
            [$_de506ef02d80cb87213a2bb0db0a70fc, $total] = $get_extranets->GetExtranets($_03e9164d0a343b742df4793268b80767);
            return new JsonPrettyResponse($this->formatter->Paginate($request, $this->formatter->FormatExtranets($_de506ef02d80cb87213a2bb0db0a70fc, $_03e9164d0a343b742df4793268b80767), $_03e9164d0a343b742df4793268b80767->GetChanged(), $total));
        } catch (InvalidArgumentException $exception) {
            throw new RestExBadRequest($exception->getMessage(), $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_c894747360c6ec5bd8169530ea" . "f9c473"], $exception);
        }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function GetOne(SecurityContext $context, ServerRequestInterface $request, GetExtranet $get_extranet, $extranet_id) : JsonPrettyResponse
    {
        try {
            $_9a2ef4ae6a5745ffe5fac33c88a222fa = $get_extranet->GetExtranet($context, $extranet_id);
            $_03e9164d0a343b742df4793268b80767 = new ExtranetFilter($context);
            $_03e9164d0a343b742df4793268b80767->Fill($this->formatter->GetRequestParams($request, $_03e9164d0a343b742df4793268b80767->GetDefaults()));
            return new JsonPrettyResponse($this->formatter->FormatExtranet($_9a2ef4ae6a5745ffe5fac33c88a222fa, $_03e9164d0a343b742df4793268b80767));
        } catch (InvalidArgumentException $e) {
            throw new RestExBadRequest($e->getMessage(), $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_c894747360c6ec5bd8169530" . "eaf9c473"], $e);
        } catch (ValidationException $e) {
            return $this->formatter->FormatValidationException($e);
        } catch (NotFoundException $e) {
            throw new RestExNotFound($e->getMessage(), $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_15f5f162efaf" . "f2443798e5cfc" . "813b02b"], $e);
        } catch (AccessDeniedException $e) {
            throw $this->GetAuthException($context, $e);
        }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function Post(CreateExtranet $create_extranet, ServerRequestInterface $request, SecurityContext $context) : JsonPrettyResponse
    {
        try {
            $params = $this->formatter->GetJson($request);
            if (!$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_7f628626dd1d55c71b1fc" . "0932ffd1d2c"]($params)) {
                $params = [];
            }
            $_9a2ef4ae6a5745ffe5fac33c88a222fa = $create_extranet->CreateExtranet($context, $params);
            return new JsonPrettyResponse($this->formatter->FormatExtranet($_9a2ef4ae6a5745ffe5fac33c88a222fa), 201);
        } catch (ValidationException $e) {
            return $this->formatter->FormatValidationException($e);
        } catch (PermissionException $e) {
            throw new RestExForbidden($e->getMessage(), $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_79bd87060993ff622ef212c1e8b6" . "a79a"], $e);
        } catch (NotFoundException $e) {
            throw new RestExNotFound($e->getMessage(), $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_a4a1018258ada" . "bb74e7b04836d8" . "d7e3b"], $e);
        }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function Put(UpdateExtranet $update_extranet, ServerRequestInterface $request, SecurityContext $context, int $extranet_id) : JsonPrettyResponse
    {
        try {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 200;
            $params = $this->formatter->GetJson($request);
            $_9a2ef4ae6a5745ffe5fac33c88a222fa = $update_extranet->UpdateExtranet($context, $extranet_id, $params);
            $response = $this->formatter->FormatExtranet($_9a2ef4ae6a5745ffe5fac33c88a222fa);
        } catch (ValidationException $e) {
            return $this->formatter->FormatValidationException($e);
        } catch (NotFoundException $e) {
            throw new RestExNotFound($e->getMessage(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_15f5f16" . "2efaff24" . "43798e5c" . "fc813b02" . "b"], $e);
        } catch (PermissionException $e) {
            throw $this->GetAuthException($context, $e);
        }
        return new JsonPrettyResponse($response, $_91dc1dd3b98a0196c76dbe68e619aa89);
    }
    
    
    
    
    
    
    
    
    
    
    public function GetUsers(GetExtranetUsers $extranet_users, SecurityContext $context, ServerRequestInterface $request, int $extranet_id)
    {
        try {
            $_03e9164d0a343b742df4793268b80767 = new UserFilter($context);
            $_03e9164d0a343b742df4793268b80767->Fill($this->formatter->GetRequestParams($request, $_03e9164d0a343b742df4793268b80767->GetDefaults()));
            
            
            [$_e4543e131c67c631b14751cc849d1310, $total] = $extranet_users->GetUsers($_03e9164d0a343b742df4793268b80767, $extranet_id);
            return new JsonPrettyResponse($this->formatter->Paginate($request, $this->formatter->FormatUsers($_e4543e131c67c631b14751cc849d1310, $_03e9164d0a343b742df4793268b80767), $_03e9164d0a343b742df4793268b80767->GetChangedWithout([$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["extranet" . "_id"]]), $total));
        } catch (InvalidArgumentException $e) {
            throw new RestExBadRequest($e->getMessage(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_c894747" . "360c6ec5" . "bd816953" . "0eaf9c47" . "3"], $e);
        } catch (ValidationException $e) {
            return $this->formatter->FormatValidationException($e);
        } catch (NotFoundException $e) {
            throw new RestExNotFound($e->getMessage(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_a4a1018258adabb74e7b0" . "4836d8d7e3b"], $e);
        }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function PutUsers(SetExtranetUsers $extranet_users, SecurityContext $context, ServerRequestInterface $request, int $extranet_id) : JsonPrettyResponse
    {
        try {
            $_17247f55ce15f647f57c3ef8bb3a474a = $this->formatter->PluckRequestIds($request);
            $_e4543e131c67c631b14751cc849d1310 = $extranet_users->UpdateExtranetUsers($context, $extranet_id, $_17247f55ce15f647f57c3ef8bb3a474a);
            return new JsonPrettyResponse($this->formatter->FormatUsers($_e4543e131c67c631b14751cc849d1310));
        } catch (ValidationException $e) {
            return $this->formatter->FormatValidationException($e);
        } catch (AccessDeniedException $e) {
            throw $this->GetAuthException($context, $e);
        } catch (NotFoundException $e) {
            throw new RestExNotFound($e->getMessage(), $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_15f5f162" . "efaff2443" . "798e5cfc8" . "13b02b"], $e);
        }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function Delete(DeleteExtranet $delete_extranet, SecurityContext $context, ServerRequestInterface $request, $extranet_id) : JsonPrettyResponse
    {
        try {
            $_ed5f03d686c37933b5943f295c6b4a43 = $request->getQueryParams();
            $delete_extranet->delete($context, $extranet_id, $_ed5f03d686c37933b5943f295c6b4a43[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_921fbf4c866dff55f6a4cab0c7be03f" . "f"]] ?? null);
            return new JsonPrettyResponse([$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["me" . "ss" . "ag" . "e"] => $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_aad7e0f" . "9751cf36" . "56148019" . "b0a08288" . "a"]]);
        } catch (ValidationException $e) {
            return $this->formatter->FormatValidationException($e);
        } catch (AccessDeniedException $e) {
            throw $this->GetAuthException($context, $e);
        } catch (NotFoundException $e) {
            throw new RestExNotFound($e->getMessage(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_15f5f162efaff24437" . "98e5cfc813b02b"], $e);
        }
    }
    
    
    
    
    
    
    
    
    
    public function GetPrimary(SecurityContext $context, GetPrimaryExtranet $get_primary_extranet)
    {
        try {
            $_9a2ef4ae6a5745ffe5fac33c88a222fa = $get_primary_extranet->GetPrimaryExtranet($context);
            return new JsonPrettyResponse($this->formatter->FormatExtranet($_9a2ef4ae6a5745ffe5fac33c88a222fa));
        } catch (PermissionException $e) {
            throw new RestExForbidden($e->getMessage(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_79bd87060993ff622ef212c1e8b" . "6a79a"], $e);
        } catch (CDNSystemException $e) {
            throw new RestExError($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_3b1fb2e9f34bda2f59863606f440af6" . "0"], 500, $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_3efc5ba7bf51ca" . "70907f5e65ab602" . "ec1"], $e);
        }
    }
}