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

$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"] = (@$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"] ?: array()) + array("gro" . "up_" . "id" => base64_decode("Z3Jv" . "dXBf" . "aWQ="), "_c894747360c6ec5bd8169530eaf" . "9c473" => base64_decode("QmFkIFJ" . "lcXVlc3" . "Q="), "_ba3845cb79c005cf3269" . "af8c83ddbe5e" => base64_decode("ZX" . "Jy" . "b3" . "I="), "_bc39899fd8a79cbcb9abb4f5d7" . "085899" => base64_decode("Z3JvdX" . "BfaWRz"), "stat" . "us" => base64_decode("c3RhdHV" . "z"));
use Analogue\ORM\Exceptions\MappingException;
use Claromentis\Core\Http\JsonPrettyResponse;
use Claromentis\Core\Http\StatusCode;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\People\Exception\NotFoundException;
use Claromentis\People\Exception\PermissionException;
use Claromentis\People\Exception\ValidationException;
use Claromentis\People\Filter\GroupFilter;
use Claromentis\People\Filter\UserFilter;
use Claromentis\People\RestFormatter;
use Claromentis\People\UseCase\CreateGroup;
use Claromentis\People\UseCase\DeleteGroup;
use Claromentis\People\UseCase\GetGroup;
use Claromentis\People\UseCase\GetGroups;
use Claromentis\People\UseCase\GetUsers;
use Claromentis\People\UseCase\UpdateGroup;
use Claromentis\People\UseCase\SetGroupUsers;
use Exception;
use InvalidArgumentException;
use Psr\Http\Message\ServerRequestInterface;
use RestExBadRequest;
use TypeError;
class GroupController extends AbstractController
{
    
    
    
    
    protected $formatter;
    
    
    
    
    protected $get_group;
    
    
    
    
    protected $get_groups;
    
    
    
    
    protected $create_group;
    
    
    
    
    protected $update_group;
    
    
    
    
    protected $set_group_users;
    
    
    
    
    protected $delete_group;
    public function __construct(RestFormatter $formatter, GetGroup $get_group, GetGroups $get_groups, CreateGroup $create_group, UpdateGroup $update_group, SetGroupUsers $set_group_users, DeleteGroup $delete_group)
    {
        $this->get_group = $get_group;
        $this->get_groups = $get_groups;
        $this->create_group = $create_group;
        $this->update_group = $update_group;
        $this->set_group_users = $set_group_users;
        $this->delete_group = $delete_group;
        $this->formatter = $formatter;
    }
    
    
    
    
    
    
    
    
    
    public function GetOne(SecurityContext $context, ServerRequestInterface $request, int $group_id) : JsonPrettyResponse
    {
        try {
            $_03e9164d0a343b742df4793268b80767 = new GroupFilter($context);
            $_03e9164d0a343b742df4793268b80767->Fill($this->formatter->GetRequestParams($request, $_03e9164d0a343b742df4793268b80767->GetDefaults()));
            $_e9208e4fb555ac989f7519e19c1da810 = $this->get_group->GetGroup($context, $group_id, $_03e9164d0a343b742df4793268b80767);
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 200;
            $response = $this->formatter->FormatGroup($_e9208e4fb555ac989f7519e19c1da810, $_03e9164d0a343b742df4793268b80767);
        } catch (InvalidArgumentException $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = StatusCode::BAD_REQUEST;
            $response = [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["sta" . "tus"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_ba3845cb79c005cf3269af8c83d" . "dbe5e"] => $e->getMessage()];
        } catch (PermissionException $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 403;
            $response = [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["sta" . "tus"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_ba3845c" . "b79c005c" . "f3269af8" . "c83ddbe5" . "e"] => $e->getMessage()];
        } catch (NotFoundException $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 404;
            $response = [$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["sta" . "tus"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_ba3845cb79c005cf3" . "269af8c83ddbe5e"] => $e->getMessage()];
        }
        return new JsonPrettyResponse($response, $_91dc1dd3b98a0196c76dbe68e619aa89);
    }
    
    
    
    
    
    
    
    
    
    public function GetList(ServerRequestInterface $request, SecurityContext $context) : JsonPrettyResponse
    {
        try {
            $_03e9164d0a343b742df4793268b80767 = new GroupFilter($context);
            $_03e9164d0a343b742df4793268b80767->Fill($this->formatter->GetRequestParams($request, $_03e9164d0a343b742df4793268b80767->GetDefaults()));
            list($_14e7d5dee412ccf516939d1e99c87733, $total) = $this->get_groups->GetGroups($_03e9164d0a343b742df4793268b80767);
            return new JsonPrettyResponse($this->formatter->Paginate($request, $this->formatter->FormatGroups($_14e7d5dee412ccf516939d1e99c87733), $_03e9164d0a343b742df4793268b80767->GetChanged(), $total));
        } catch (InvalidArgumentException $exception) {
            throw new RestExBadRequest($exception->getMessage(), $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_c894747360c6ec5bd8169530ea" . "f9c473"], $exception);
        }
    }
    
    
    
    
    
    
    
    
    public function GetUsers(ServerRequestInterface $request, SecurityContext $context, GetGroup $get_group, GetUsers $get_users)
    {
        try {
            $group_id = $this->formatter->GetRequestParam($request, $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["gro" . "up_" . "id"]);
            $_eea5f8bfe99a09bd4d06764e8020a0b8 = new GroupFilter($context);
            $_e9208e4fb555ac989f7519e19c1da810 = $get_group->GetGroup($context, $group_id, $_eea5f8bfe99a09bd4d06764e8020a0b8);
            $_7945aa6526b98d01ea0f6f6f7037bd6e = new UserFilter($context);
            $_7945aa6526b98d01ea0f6f6f7037bd6e->Fill($this->formatter->GetRequestParams($request, $_7945aa6526b98d01ea0f6f6f7037bd6e->GetDefaults()));
            $_7945aa6526b98d01ea0f6f6f7037bd6e->SetGroupIds($_e9208e4fb555ac989f7519e19c1da810->id);
            list($_e4543e131c67c631b14751cc849d1310, $total) = $get_users->GetUsers($_7945aa6526b98d01ea0f6f6f7037bd6e);
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 200;
            $response = $this->formatter->Paginate($request, $this->formatter->FormatUsers($_e4543e131c67c631b14751cc849d1310, $_7945aa6526b98d01ea0f6f6f7037bd6e), $_7945aa6526b98d01ea0f6f6f7037bd6e->GetChangedWithout([$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_bc39899fd8a79cbcb9abb4f5" . "d7085899"]]), $total);
        } catch (TypeError|InvalidArgumentException $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 400;
            $response = [$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["stat" . "us"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_ba3845cb79c005cf3269af8c" . "83ddbe5e"] => $e->getMessage()];
        } catch (PermissionException $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 401;
            $response = [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["statu" . "s"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_ba3845cb79c" . "005cf3269af8" . "c83ddbe5e"] => $e->getMessage()];
        } catch (NotFoundException $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 404;
            $response = [$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["st" . "at" . "us"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_ba3845cb79" . "c005cf3269a" . "f8c83ddbe5e"] => $e->getMessage()];
        } catch (Exception $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 500;
            $response = [$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["st" . "at" . "us"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_ba3845cb79c005cf3269af8c83ddbe5" . "e"] => $e->getMessage()];
        }
        return new JsonPrettyResponse($response, $_91dc1dd3b98a0196c76dbe68e619aa89);
    }
    
    
    
    
    
    
    
    
    public function Post(ServerRequestInterface $request, SecurityContext $context) : JsonPrettyResponse
    {
        
        
        
        
        $_26a9043be266181cda9ab75d31198d09 = $this->create_group;
        try {
            $attributes = $this->formatter->GetJson($request);
            $_e9208e4fb555ac989f7519e19c1da810 = $_26a9043be266181cda9ab75d31198d09->CreateGroup($context, $attributes);
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 201;
            $response = $this->formatter->FormatGroup($_e9208e4fb555ac989f7519e19c1da810);
        } catch (ValidationException $e) {
            return $this->formatter->FormatValidationException($e);
        } catch (InvalidArgumentException $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 400;
            $response = [$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["statu" . "s"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_ba3845cb79c005cf3269af8c83" . "ddbe5e"] => $e->getMessage()];
        } catch (PermissionException $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 401;
            $response = [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["st" . "at" . "us"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_ba3845cb79c" . "005cf3269af8" . "c83ddbe5e"] => $e->getMessage()];
        } catch (Exception $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 500;
            $response = [$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["sta" . "tus"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_ba3845cb79c005cf3269af8c83ddbe5" . "e"] => $e->getMessage()];
        }
        return new JsonPrettyResponse($response, $_91dc1dd3b98a0196c76dbe68e619aa89);
    }
    
    
    
    
    
    
    
    
    
    public function Put(ServerRequestInterface $request, SecurityContext $context, int $group_id) : JsonPrettyResponse
    {
        
        
        
        
        $_39c6319b93717cd36fbacbd94baa4fbd = $this->update_group;
        try {
            $_e9208e4fb555ac989f7519e19c1da810 = $_39c6319b93717cd36fbacbd94baa4fbd->UpdateGroup($context, $group_id, $this->formatter->GetJson($request));
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 200;
            $response = $this->formatter->FormatGroup($_e9208e4fb555ac989f7519e19c1da810);
        } catch (TypeError|InvalidArgumentException $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 400;
            $response = [$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["sta" . "tus"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_ba3845cb79c005cf" . "3269af8c83ddbe5e"] => $e->getMessage()];
        } catch (PermissionException $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 401;
            $response = [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["sta" . "tus"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_ba3845cb7" . "9c005cf326" . "9af8c83ddb" . "e5e"] => $e->getMessage()];
        } catch (NotFoundException $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 404;
            $response = [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["sta" . "tus"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_ba3845cb79c00" . "5cf3269af8c83d" . "dbe5e"] => $e->getMessage()];
        } catch (Exception $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 500;
            $response = [$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["st" . "at" . "us"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_ba3845cb79c005cf3269af8c83dd" . "be5e"] => $e->getMessage()];
        }
        return new JsonPrettyResponse($response, $_91dc1dd3b98a0196c76dbe68e619aa89);
    }
    
    
    
    
    
    
    
    public function PutUsers(ServerRequestInterface $request, SecurityContext $context, int $group_id)
    {
        try {
            $_e4543e131c67c631b14751cc849d1310 = $this->set_group_users->SetGroupUsers($context, $group_id, $this->formatter->PluckRequestIds($request));
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 200;
            $response = $this->formatter->FormatUsers($_e4543e131c67c631b14751cc849d1310);
        } catch (TypeError|InvalidArgumentException|ValidationException $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 400;
            $response = [$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["statu" . "s"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_ba3845cb79c" . "005cf3269af8" . "c83ddbe5e"] => $e->getMessage()];
        } catch (PermissionException $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 401;
            $response = [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["sta" . "tus"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_ba3845cb79c005cf" . "3269af8c83ddbe5e"] => $e->getMessage()];
        } catch (NotFoundException $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 404;
            $response = [$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["stat" . "us"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_ba3845cb79c005cf3269af8c83" . "ddbe5e"] => $e->getMessage()];
        } catch (Exception $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 500;
            $response = [$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["st" . "at" . "us"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_ba3845cb79c005cf3269af8c83ddbe" . "5e"] => $e->getMessage()];
        }
        return new JsonPrettyResponse($response, $_91dc1dd3b98a0196c76dbe68e619aa89);
    }
    
    
    
    
    
    
    
    
    public function Delete(SecurityContext $context, $group_id) : JsonPrettyResponse
    {
        try {
            $this->delete_group->DeleteGroup($context, $group_id);
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 204;
            $response = null;
        } catch (TypeError|InvalidArgumentException $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 400;
            $response = [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["stat" . "us"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_ba3845cb7" . "9c005cf326" . "9af8c83ddb" . "e5e"] => $e->getMessage()];
        } catch (PermissionException $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 401;
            $response = [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["sta" . "tus"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_ba3845cb79c0" . "05cf3269af8c8" . "3ddbe5e"] => $e->getMessage()];
        } catch (NotFoundException $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 404;
            $response = [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["statu" . "s"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_ba3845cb79c005cf3269af8c8" . "3ddbe5e"] => $e->getMessage()];
        } catch (MappingException $e) {
            $_91dc1dd3b98a0196c76dbe68e619aa89 = 500;
            $response = [$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["statu" . "s"] => $_91dc1dd3b98a0196c76dbe68e619aa89, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_ba3845cb79c005cf3269af8c83ddbe5" . "e"] => $e->getMessage()];
        }
        return new JsonPrettyResponse($response, $_91dc1dd3b98a0196c76dbe68e619aa89);
    }
}