<?php
namespace Claromentis\People;

$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"] ?: array()) + array("paren" . "t_id" => base64_decode("cGFyZW" . "50X2lk"), "_17bccc635eff910e2579ec" . "983b82869e" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X3J" . "vbGVfdXNlcnM="), "_4efca57498a2951578bf2e1b" . "a92d64d7" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X3VzZ" . "XJfZ3JvdXBz"), "_8b281d2a39e2" . "069eea1195ce9" . "42083ca" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X2dyb3VwX3Vz" . "ZXJz"), "_ece5dd81572732c3e2" . "866ce42bb75431" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X3VzZXJfcm9sZ" . "XM="), "grou" . "p_id" => base64_decode("Z3JvdXBf" . "aWQ="), "_b9aada43a4" . "3a79c46a1fe" . "6be54802639" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X3Jvb" . "GVz"), "mess" . "age" => base64_decode("bWVzc2Fn" . "ZQ=="), "_f241e37" . "8ff0d557" . "8f1d3463" . "03ac4aae" . "f" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X2dyb3Vwcw" . "=="), "_3c57ea5b6da2c9369336cdba5b9cc" . "f1a" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X3VzZX" . "I="), "role_" . "id" => base64_decode("cm9sZV9p" . "ZA=="), "extranet" . "_id" => base64_decode("ZXh0cmFuZXRfaW" . "Q="), "_707bfdcf1b13" . "50e184bf7273b" . "2cf1602" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X2V4dHJh" . "bmV0X3VzZXJz"), "_c9a58ab51fadf2ed15b0d0" . "ce8a09e506" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X3VzZ" . "XJfc3Vib3JkaW5hdGVz"), "_fc9d7314a9d9" . "958d8fa0a403b" . "a8ff197" => base64_decode("Z2V0X" . "2NsYX" . "Nz"), "_c78f29e7b113c7a4d29fe3c446818" . "1e9" => base64_decode("ZXJyb3" . "Jz"), "_4d707fab" . "93bebb00b" . "be69e8159" . "697c90" => base64_decode(""), "_bf2063735d" . "11aa24bb98d" . "039eb8aeeda" => base64_decode("cGVvcGxlLnJlc3QuZ2" . "V0X2V4dHJhbmV0"), "us" . "er" . "_i" . "d" => base64_decode("dXNlc" . "l9pZA" . "=="), "_ba3845cb79c005cf3269af8c83ddb" . "e5e" => base64_decode("ZXJyb3" . "I="), "_326521a4b3c8a9c8b" . "77634f1f44b3e5a" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X" . "2dyb3Vw"), "stat" . "us" => base64_decode("c3RhdH" . "Vz"));
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"]["user_" . "id"] => $_24e0e36600d6af77406a44bb618a6253->id];
        
        
        $_24e0e36600d6af77406a44bb618a6253->subordinates_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_c9a58ab51fadf2ed15b0d0c" . "e8a09e506"], $_3c76edc0804ad93f2e140288dfafba27);
        
        
        
        
        
        
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_fc9d7314a9d9958d8fa0a" . "403ba8ff197"]($_24e0e36600d6af77406a44bb618a6253->extranet) == Extranet::class) {
            $_24e0e36600d6af77406a44bb618a6253->extranet_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_bf2063735d11aa" . "24bb98d039eb8ae" . "eda"], [$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["ext" . "ran" . "et_" . "id"] => $_24e0e36600d6af77406a44bb618a6253->extranet->id]);
        } else {
            $_24e0e36600d6af77406a44bb618a6253->extranet_url = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_4d707fab93bebb00bbe69e8159" . "697c90"];
        }
        $_24e0e36600d6af77406a44bb618a6253->groups_url = $this->GenerateUrl($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_4efca57498a2951578bf2e1ba92d64" . "d7"], $_3c76edc0804ad93f2e140288dfafba27);
        $_24e0e36600d6af77406a44bb618a6253->roles_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_ece5dd81572732c3e2866ce" . "42bb75431"], $_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"]["_326521a4b3c8a9c8b77634f1f" . "44b3e5a"], [$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["group" . "_id"] => $_e9208e4fb555ac989f7519e19c1da810->parent_id]) : null;
        $_e9208e4fb555ac989f7519e19c1da810->owner_url = $_e9208e4fb555ac989f7519e19c1da810->owner_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_3c57ea5b6da2c936" . "9336cdba5b9ccf1a"], [$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["user_i" . "d"] => $_e9208e4fb555ac989f7519e19c1da810->owner_id]) : null;
        $_e9208e4fb555ac989f7519e19c1da810->extranet_url = $_e9208e4fb555ac989f7519e19c1da810->extranet_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_bf2063735d11aa24bb98d039eb8aee" . "da"], [$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["extran" . "et_id"] => $_e9208e4fb555ac989f7519e19c1da810->extranet_id]) : null;
        $_e9208e4fb555ac989f7519e19c1da810->users_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_8b281d2a39e2069eea1195ce942" . "083ca"], [$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["gr" . "ou" . "p_" . "id"] => $_e9208e4fb555ac989f7519e19c1da810->id]);
        $_e9208e4fb555ac989f7519e19c1da810->subgroups_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_f241e378ff0d5578f1d34630" . "3ac4aaef"], [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["pare" . "nt_i" . "d"] => $_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["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_17bccc635eff910e2579ec983b8" . "2869e"], [$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["ro" . "le" . "_i" . "d"] => $_d1071a032215f0eb5c4a8ef175f7049d->id]);
        $_d1071a032215f0eb5c4a8ef175f7049d->owner_url = $_d1071a032215f0eb5c4a8ef175f7049d->owner_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_3c57ea5b6da2c9369336cdba5" . "b9ccf1a"], [$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["us" . "er" . "_i" . "d"] => $_d1071a032215f0eb5c4a8ef175f7049d->owner_id]) : null;
        $_d1071a032215f0eb5c4a8ef175f7049d->extranet_url = $_d1071a032215f0eb5c4a8ef175f7049d->extranet_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_bf2063735d11aa24bb98" . "d039eb8aeeda"], [$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["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["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_3c57ea5b6" . "da2c936933" . "6cdba5b9cc" . "f1a"], [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["user_" . "id"] => $_9a2ef4ae6a5745ffe5fac33c88a222fa->admin_id]) : null;
        $_9a2ef4ae6a5745ffe5fac33c88a222fa->groups_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_f241e378ff0d5578f1d346303ac" . "4aaef"], [$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["extranet_i" . "d"] => $_9a2ef4ae6a5745ffe5fac33c88a222fa->id]);
        $_9a2ef4ae6a5745ffe5fac33c88a222fa->roles_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_b9aada43a43a79c46a1fe6be5" . "4802639"], [$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["extr" . "anet" . "_id"] => $_9a2ef4ae6a5745ffe5fac33c88a222fa->id]);
        $_9a2ef4ae6a5745ffe5fac33c88a222fa->users_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_707bfdcf" . "1b1350e18" . "4bf7273b2" . "cf1602"], [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["extra" . "net_i" . "d"] => $_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["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_ba3845cb79c005cf3269af8c83dd" . "be5e"] => true, $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["statu" . "s"] => StatusCode::BAD_REQUEST, $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["messa" . "ge"] => $exception->getMessage(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_c78f29e7b113c7a4d29fe3c4468181" . "e9"] => $exception->getValidationErrors()];
        return new JsonPrettyResponse($data, StatusCode::BAD_REQUEST);
    }
    
    
    
    
    
    
    
    public function FormatPermissionException(PermissionException $exception) : JsonPrettyResponse
    {
        $data = [$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_ba3845cb" . "79c005cf3" . "269af8c83" . "ddbe5e"] => true, $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["statu" . "s"] => StatusCode::FORBIDDEN, $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["mess" . "age"] => $exception->getMessage(), $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_c78f29e" . "7b113c7a" . "4d29fe3c" . "4468181e" . "9"] => $exception->getErrors()];
        return new JsonPrettyResponse($data, StatusCode::FORBIDDEN);
    }
}