<?php
namespace Claromentis\People;

$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"] ?: array()) + array("_4efca57498a2951578bf2" . "e1ba92d64d7" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X3VzZXJfZ3JvdXB" . "z"), "_707bfdcf1b1350e184b" . "f7273b2cf1602" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X2V4dHJhbmV0X3" . "VzZXJz"), "mes" . "sag" . "e" => base64_decode("bWVzc" . "2FnZQ" . "=="), "_f241e378ff0d5578f1d346303ac" . "4aaef" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X2dyb3Vwcw" . "=="), "_4d707fab93bebb" . "00bbe69e8159697" . "c90" => base64_decode(""), "us" . "er" . "_i" . "d" => base64_decode("dXNlcl9p" . "ZA=="), "pa" . "re" . "nt" . "_i" . "d" => base64_decode("cGFyZW50X2" . "lk"), "_c9a58ab51fadf2ed15b0" . "d0ce8a09e506" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X3VzZXJfc3Vib3JkaW5hdG" . "Vz"), "_3c57ea5b" . "6da2c9369" . "336cdba5b" . "9ccf1a" => base64_decode("cGVvcGxlLnJlc3Qu" . "Z2V0X3VzZXI="), "_c78f29e7b113c7a" . "4d29fe3c4468181e" . "9" => base64_decode("ZXJy" . "b3Jz"), "_ba3845cb79c005cf32" . "69af8c83ddbe5e" => base64_decode("ZXJyb3I" . "="), "_8b281d2a39e2069eea" . "1195ce942083ca" => base64_decode("cGVvcGxlLnJlc3" . "QuZ2V0X2dyb3Vw" . "X3VzZXJz"), "_b9aada43a" . "43a79c46a1" . "fe6be54802" . "639" => base64_decode("cGVvcGxlLnJlc3QuZ2" . "V0X3JvbGVz"), "rol" . "e_i" . "d" => base64_decode("cm9sZV9" . "pZA=="), "statu" . "s" => base64_decode("c3Rh" . "dHVz"), "extrane" . "t_id" => base64_decode("ZXh0cmF" . "uZXRfaW" . "Q="), "_17bccc635eff910e2579ec983" . "b82869e" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X3JvbGVf" . "dXNlcnM="), "grou" . "p_id" => base64_decode("Z3Jvd" . "XBfaW" . "Q="), "_bf2063735d11aa24bb98d039eb8aee" . "da" => base64_decode("cGVvcGxlLnJlc" . "3QuZ2V0X2V4dH" . "JhbmV0"), "_fc9d7314" . "a9d9958d8" . "fa0a403ba" . "8ff197" => base64_decode("Z2V0X2NsY" . "XNz"), "_326521a4b3c8a9c8b77634f" . "1f44b3e5a" => base64_decode("cGVvcGxlLnJlc3QuZ2V0" . "X2dyb3Vw"), "_ece5dd8157" . "2732c3e2866" . "ce42bb75431" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X3VzZXJf" . "cm9sZXM="));
use Analogue\ORM\Entity;
use Analogue\ORM\EntityCollection;
use Claromentis\Core\CDN\CDNException;
use Claromentis\Core\Http\HttpUtil;
use Claromentis\Core\Http\JsonPrettyResponse;
use Claromentis\Core\Http\StatusCode;
use Claromentis\People\Entity\Extranet;
use Claromentis\People\Entity\Group;
use Claromentis\People\Entity\Role;
use Claromentis\People\Exception\PermissionException;
use Claromentis\People\Exception\ValidationException;
use Claromentis\People\Entity\User;
use Claromentis\People\Filter\ExtranetFilter;
use Claromentis\People\Filter\Filter;
use Claromentis\People\Filter\GroupFilter;
use Claromentis\People\Filter\RoleFilter;
use Claromentis\People\Filter\UserFilter;
use Date;
use DateTime;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;









class RestFormatter extends \Claromentis\Core\REST\RestFormatter
{
    
    
    
    
    protected $people_url_generator;
    
    
    
    
    
    
    
    
    public function __construct(UrlGeneratorInterface $url_generator, UrlGenerator $_7452672603cdd8a902a1e7fcb9a96f85, HttpUtil $_019f644d80568a97cf247afb364302a5)
    {
        parent::__construct($url_generator, $_019f644d80568a97cf247afb364302a5);
        $this->people_url_generator = $_7452672603cdd8a902a1e7fcb9a96f85;
    }
    
    
    
    
    
    
    public function Date($_67a0d624aebcceb0abd5ce56a53ff06f)
    {
        return $this->DateIso8601($_67a0d624aebcceb0abd5ce56a53ff06f);
    }
    
    
    
    
    public function EntityAttribute($value)
    {
        if ($value instanceof Entity) {
            return $this->FormatPeopleEntity($value);
        }
        return parent::EntityAttribute($value);
    }
    
    
    
    
    
    
    
    
    
    
    public function FormatPeopleEntity(Entity $_ba1f6e266e3ebd29f620349be8ec92a5, Filter $_03e9164d0a343b742df4793268b80767 = null) : array
    {
        if ($_ba1f6e266e3ebd29f620349be8ec92a5 instanceof User) {
            return $this->FormatUser($_ba1f6e266e3ebd29f620349be8ec92a5);
        }
        if ($_ba1f6e266e3ebd29f620349be8ec92a5 instanceof Group) {
            return $this->FormatGroup($_ba1f6e266e3ebd29f620349be8ec92a5);
        }
        if ($_ba1f6e266e3ebd29f620349be8ec92a5 instanceof Role) {
            return $this->FormatRole($_ba1f6e266e3ebd29f620349be8ec92a5);
        }
        if ($_ba1f6e266e3ebd29f620349be8ec92a5 instanceof Extranet) {
            return $this->FormatExtranet($_ba1f6e266e3ebd29f620349be8ec92a5);
        }
        return parent::Entity($_ba1f6e266e3ebd29f620349be8ec92a5, $_03e9164d0a343b742df4793268b80767);
    }
    
    
    
    
    
    
    
    
    public function FormatUser(User $_24e0e36600d6af77406a44bb618a6253, UserFilter $_03e9164d0a343b742df4793268b80767 = null) : array
    {
        try {
            $_24e0e36600d6af77406a44bb618a6253->photo_url = $this->http_util->CreateInternalLink(\User::GetPhotoUrl($_24e0e36600d6af77406a44bb618a6253->id, false));
        } catch (CDNException $exception) {
            
            
            $_24e0e36600d6af77406a44bb618a6253->photo_url = null;
        }
        $_3c76edc0804ad93f2e140288dfafba27 = [$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["us" . "er" . "_i" . "d"] => $_24e0e36600d6af77406a44bb618a6253->id];
        
        
        $_24e0e36600d6af77406a44bb618a6253->subordinates_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_c9a58ab51fadf2ed15" . "b0d0ce8a09e506"], $_3c76edc0804ad93f2e140288dfafba27);
        
        
        
        
        
        
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_fc9d7314a9d9958d8fa0a403ba8ff1" . "97"]($_24e0e36600d6af77406a44bb618a6253->extranet) == Extranet::class) {
            $_24e0e36600d6af77406a44bb618a6253->extranet_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_bf2063735d11aa24bb98d039" . "eb8aeeda"], [$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["ext" . "ran" . "et_" . "id"] => $_24e0e36600d6af77406a44bb618a6253->extranet->id]);
        } else {
            $_24e0e36600d6af77406a44bb618a6253->extranet_url = $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_4d707fab93bebb00bb" . "e69e8159697c90"];
        }
        $_24e0e36600d6af77406a44bb618a6253->groups_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_4efca57498a2951578bf2e1ba9" . "2d64d7"], $_3c76edc0804ad93f2e140288dfafba27);
        $_24e0e36600d6af77406a44bb618a6253->roles_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_ece5dd81572732c3e2866c" . "e42bb75431"], $_3c76edc0804ad93f2e140288dfafba27);
        return $this->Entity($_24e0e36600d6af77406a44bb618a6253, $_03e9164d0a343b742df4793268b80767);
    }
    
    
    
    
    
    
    
    
    public function FormatUsers(EntityCollection $_e4543e131c67c631b14751cc849d1310, UserFilter $_03e9164d0a343b742df4793268b80767 = null) : array
    {
        $_355d5d19fc271adaa25aaa15960925f5 = [];
        foreach ($_e4543e131c67c631b14751cc849d1310 as $_24e0e36600d6af77406a44bb618a6253) {
            $_355d5d19fc271adaa25aaa15960925f5[] = $this->FormatUser($_24e0e36600d6af77406a44bb618a6253, $_03e9164d0a343b742df4793268b80767);
        }
        return $_355d5d19fc271adaa25aaa15960925f5;
    }
    
    
    
    
    
    
    
    
    public function FormatGroup(Group $_e9208e4fb555ac989f7519e19c1da810, GroupFilter $_03e9164d0a343b742df4793268b80767 = null) : array
    {
        $_e9208e4fb555ac989f7519e19c1da810->parent_url = $_e9208e4fb555ac989f7519e19c1da810->parent_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_326521a4" . "b3c8a9c8b" . "77634f1f4" . "4b3e5a"], [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["group_i" . "d"] => $_e9208e4fb555ac989f7519e19c1da810->parent_id]) : null;
        $_e9208e4fb555ac989f7519e19c1da810->owner_url = $_e9208e4fb555ac989f7519e19c1da810->owner_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_3c57ea5b6da2c9369336cdba" . "5b9ccf1a"], [$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["user_" . "id"] => $_e9208e4fb555ac989f7519e19c1da810->owner_id]) : null;
        $_e9208e4fb555ac989f7519e19c1da810->extranet_url = $_e9208e4fb555ac989f7519e19c1da810->extranet_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_bf2063735d11aa24bb98d039" . "eb8aeeda"], [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["extrane" . "t_id"] => $_e9208e4fb555ac989f7519e19c1da810->extranet_id]) : null;
        $_e9208e4fb555ac989f7519e19c1da810->users_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_8b281d2a" . "39e2069ee" . "a1195ce94" . "2083ca"], [$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["gr" . "ou" . "p_" . "id"] => $_e9208e4fb555ac989f7519e19c1da810->id]);
        $_e9208e4fb555ac989f7519e19c1da810->subgroups_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_f241e378ff0d5578f1d" . "346303ac4aaef"], [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["par" . "ent" . "_id"] => $_e9208e4fb555ac989f7519e19c1da810->id]);
        return $this->Entity($_e9208e4fb555ac989f7519e19c1da810, $_03e9164d0a343b742df4793268b80767);
    }
    
    
    
    
    
    
    
    
    public function FormatGroups(EntityCollection $_14e7d5dee412ccf516939d1e99c87733, GroupFilter $_03e9164d0a343b742df4793268b80767 = null) : array
    {
        $_355d5d19fc271adaa25aaa15960925f5 = [];
        foreach ($_14e7d5dee412ccf516939d1e99c87733 as $_e9208e4fb555ac989f7519e19c1da810) {
            $_355d5d19fc271adaa25aaa15960925f5[] = $this->FormatGroup($_e9208e4fb555ac989f7519e19c1da810, $_03e9164d0a343b742df4793268b80767);
        }
        return $_355d5d19fc271adaa25aaa15960925f5;
    }
    
    
    
    
    
    
    
    
    public function FormatRole(Role $_d1071a032215f0eb5c4a8ef175f7049d, RoleFilter $_03e9164d0a343b742df4793268b80767 = null) : array
    {
        $_d1071a032215f0eb5c4a8ef175f7049d->users_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_17bccc635ef" . "f910e2579ec9" . "83b82869e"], [$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["role_" . "id"] => $_d1071a032215f0eb5c4a8ef175f7049d->id]);
        $_d1071a032215f0eb5c4a8ef175f7049d->owner_url = $_d1071a032215f0eb5c4a8ef175f7049d->owner_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_3c57ea5b6da2c9369336" . "cdba5b9ccf1a"], [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["user" . "_id"] => $_d1071a032215f0eb5c4a8ef175f7049d->owner_id]) : null;
        $_d1071a032215f0eb5c4a8ef175f7049d->extranet_url = $_d1071a032215f0eb5c4a8ef175f7049d->extranet_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_bf2063735d11aa24bb98" . "d039eb8aeeda"], [$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["extrane" . "t_id"] => $_d1071a032215f0eb5c4a8ef175f7049d->extranet_id]) : null;
        return $this->Entity($_d1071a032215f0eb5c4a8ef175f7049d, $_03e9164d0a343b742df4793268b80767);
    }
    
    
    
    
    
    
    
    
    public function FormatRoles(EntityCollection $_23ab4dd81b6c619f47099ef7c2485a12, RoleFilter $_03e9164d0a343b742df4793268b80767 = null) : array
    {
        $_355d5d19fc271adaa25aaa15960925f5 = [];
        foreach ($_23ab4dd81b6c619f47099ef7c2485a12 as $_d1071a032215f0eb5c4a8ef175f7049d) {
            $_355d5d19fc271adaa25aaa15960925f5[] = $this->FormatRole($_d1071a032215f0eb5c4a8ef175f7049d, $_03e9164d0a343b742df4793268b80767);
        }
        return $_355d5d19fc271adaa25aaa15960925f5;
    }
    
    
    
    
    
    
    
    
    public function FormatExtranet(Extranet $_9a2ef4ae6a5745ffe5fac33c88a222fa, ExtranetFilter $_03e9164d0a343b742df4793268b80767 = null) : array
    {
        $_9a2ef4ae6a5745ffe5fac33c88a222fa->logo_url = $this->people_url_generator->getExtranetLogoUrl($_9a2ef4ae6a5745ffe5fac33c88a222fa);
        $_9a2ef4ae6a5745ffe5fac33c88a222fa->admin_url = $_9a2ef4ae6a5745ffe5fac33c88a222fa->admin_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_3c57ea5b6da2c9369336cdba5b" . "9ccf1a"], [$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["user_" . "id"] => $_9a2ef4ae6a5745ffe5fac33c88a222fa->admin_id]) : null;
        $_9a2ef4ae6a5745ffe5fac33c88a222fa->groups_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_f241e378ff0d5578f1d346" . "303ac4aaef"], [$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["extranet_i" . "d"] => $_9a2ef4ae6a5745ffe5fac33c88a222fa->id]);
        $_9a2ef4ae6a5745ffe5fac33c88a222fa->roles_url = $this->GenerateUrl($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_b9aada43a43a79c46a1fe6be54802" . "639"], [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["extra" . "net_i" . "d"] => $_9a2ef4ae6a5745ffe5fac33c88a222fa->id]);
        $_9a2ef4ae6a5745ffe5fac33c88a222fa->users_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_707bfdcf1b1350e184" . "bf7273b2cf1602"], [$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["extr" . "anet" . "_id"] => $_9a2ef4ae6a5745ffe5fac33c88a222fa->id]);
        return $this->Entity($_9a2ef4ae6a5745ffe5fac33c88a222fa, $_03e9164d0a343b742df4793268b80767);
    }
    
    
    
    
    
    
    
    
    
    public function FormatExtranets(EntityCollection $_de506ef02d80cb87213a2bb0db0a70fc, ExtranetFilter $_03e9164d0a343b742df4793268b80767 = null) : array
    {
        $_355d5d19fc271adaa25aaa15960925f5 = [];
        foreach ($_de506ef02d80cb87213a2bb0db0a70fc as $_9a2ef4ae6a5745ffe5fac33c88a222fa) {
            $_355d5d19fc271adaa25aaa15960925f5[] = $this->FormatExtranet($_9a2ef4ae6a5745ffe5fac33c88a222fa, $_03e9164d0a343b742df4793268b80767);
        }
        return $_355d5d19fc271adaa25aaa15960925f5;
    }
    
    
    
    
    
    
    
    public function FormatValidationException(ValidationException $exception) : JsonPrettyResponse
    {
        $data = [$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_ba3845cb79c005cf" . "3269af8c83ddbe5e"] => true, $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["statu" . "s"] => StatusCode::BAD_REQUEST, $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["messag" . "e"] => $exception->getMessage(), $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_c78f29e7b11" . "3c7a4d29fe3c" . "4468181e9"] => $exception->getValidationErrors()];
        return new JsonPrettyResponse($data, StatusCode::BAD_REQUEST);
    }
    
    
    
    
    
    
    
    public function FormatPermissionException(PermissionException $exception) : JsonPrettyResponse
    {
        $data = [$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_ba3845cb79c005cf" . "3269af8c83ddbe5e"] => true, $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["stat" . "us"] => StatusCode::FORBIDDEN, $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["messag" . "e"] => $exception->getMessage(), $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_c78f29e7b113c7a4" . "d29fe3c4468181e9"] => $exception->getErrors()];
        return new JsonPrettyResponse($data, StatusCode::FORBIDDEN);
    }
}