<?php
namespace Claromentis\People;

$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"] ?: array()) + array("_bf2063735d11aa24bb" . "98d039eb8aeeda" => base64_decode("cGVvcGxlLnJlc3QuZ2V0" . "X2V4dHJhbmV0"), "_ece5dd81572732c3e" . "2866ce42bb75431" => base64_decode("cGVvcGxlLnJlc3QuZ2V0" . "X3VzZXJfcm9sZXM="), "_ba3845cb79c005cf3269af8c8" . "3ddbe5e" => base64_decode("ZXJyb3" . "I="), "_8b281d2a39e2069" . "eea1195ce942083c" . "a" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X" . "2dyb3VwX3VzZXJz"), "statu" . "s" => base64_decode("c3Rhd" . "HVz"), "paren" . "t_id" => base64_decode("cGFyZW5" . "0X2lk"), "group" . "_id" => base64_decode("Z3JvdXB" . "faWQ="), "role_" . "id" => base64_decode("cm9sZV9p" . "ZA=="), "_b9aada43a43a79c46a1fe6" . "be54802639" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X3" . "JvbGVz"), "_4d707fab93bebb00bbe69e8159697" . "c90" => base64_decode(""), "_c78f29e7b113c7a4" . "d29fe3c4468181e9" => base64_decode("ZXJyb3" . "Jz"), "_17bccc635eff910e2579ec983b82869" . "e" => base64_decode("cGVvcGxlL" . "nJlc3QuZ2" . "V0X3JvbGV" . "fdXNlcnM="), "user_" . "id" => base64_decode("dXNlcl" . "9pZA=="), "_c9a58ab51fadf2ed" . "15b0d0ce8a09e506" => base64_decode("cGVvcGxlLnJlc3Qu" . "Z2V0X3VzZXJfc3Vi" . "b3JkaW5hdGVz"), "messa" . "ge" => base64_decode("bWVzc2FnZQ=" . "="), "_fc9d7314a9d99" . "58d8fa0a403ba8" . "ff197" => base64_decode("Z2V" . "0X2" . "NsY" . "XNz"), "extrane" . "t_id" => base64_decode("ZXh0cmFuZXRfa" . "WQ="), "_326521a4" . "b3c8a9c8b" . "77634f1f4" . "4b3e5a" => base64_decode("cGVvcGxlLnJlc3QuZ" . "2V0X2dyb3Vw"), "_3c57ea5b6da2c9369336cdba5b9c" . "cf1a" => base64_decode("cGVvcGxlLnJlc3Qu" . "Z2V0X3VzZXI="), "_707bfdcf1b1350e184bf72" . "73b2cf1602" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X2V" . "4dHJhbmV0X3VzZXJz"), "_4efca57498a2951578bf2e1ba92" . "d64d7" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X3VzZXJfZ3JvdX" . "Bz"), "_f241e378ff0d5578f1d" . "346303ac4aaef" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X" . "2dyb3Vwcw=="));
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["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_c9a58ab51fadf2ed15b0d0c" . "e8a09e506"], $_3c76edc0804ad93f2e140288dfafba27);
        
        
        
        
        
        
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_fc9d7314a9d99" . "58d8fa0a403ba8" . "ff197"]($_24e0e36600d6af77406a44bb618a6253->extranet) == Extranet::class) {
            $_24e0e36600d6af77406a44bb618a6253->extranet_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_bf2063735d11" . "aa24bb98d039e" . "b8aeeda"], [$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["ext" . "ran" . "et_" . "id"] => $_24e0e36600d6af77406a44bb618a6253->extranet->id]);
        } else {
            $_24e0e36600d6af77406a44bb618a6253->extranet_url = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_4d707fab93beb" . "b00bbe69e81596" . "97c90"];
        }
        $_24e0e36600d6af77406a44bb618a6253->groups_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_4efca57498a2951578bf2e1ba92d6" . "4d7"], $_3c76edc0804ad93f2e140288dfafba27);
        $_24e0e36600d6af77406a44bb618a6253->roles_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_ece5dd8157" . "2732c3e2866" . "ce42bb75431"], $_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["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_326521a4b3c8a9c8b77634" . "f1f44b3e5a"], [$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["group_i" . "d"] => $_e9208e4fb555ac989f7519e19c1da810->parent_id]) : null;
        $_e9208e4fb555ac989f7519e19c1da810->owner_url = $_e9208e4fb555ac989f7519e19c1da810->owner_id ? $this->GenerateUrl($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_3c57ea5b6da2" . "c9369336cdba5" . "b9ccf1a"], [$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["user_i" . "d"] => $_e9208e4fb555ac989f7519e19c1da810->owner_id]) : null;
        $_e9208e4fb555ac989f7519e19c1da810->extranet_url = $_e9208e4fb555ac989f7519e19c1da810->extranet_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_bf20637" . "35d11aa2" . "4bb98d03" . "9eb8aeed" . "a"], [$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["extra" . "net_i" . "d"] => $_e9208e4fb555ac989f7519e19c1da810->extranet_id]) : null;
        $_e9208e4fb555ac989f7519e19c1da810->users_url = $this->GenerateUrl($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_8b281d2a39e2069eea1195ce942" . "083ca"], [$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["gr" . "ou" . "p_" . "id"] => $_e9208e4fb555ac989f7519e19c1da810->id]);
        $_e9208e4fb555ac989f7519e19c1da810->subgroups_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_f241e378ff0d5578f" . "1d346303ac4aaef"], [$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["parent_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["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_17bccc635eff910e257" . "9ec983b82869e"], [$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["role" . "_id"] => $_d1071a032215f0eb5c4a8ef175f7049d->id]);
        $_d1071a032215f0eb5c4a8ef175f7049d->owner_url = $_d1071a032215f0eb5c4a8ef175f7049d->owner_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_3c57ea5b6da2c9369336cd" . "ba5b9ccf1a"], [$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["user_i" . "d"] => $_d1071a032215f0eb5c4a8ef175f7049d->owner_id]) : null;
        $_d1071a032215f0eb5c4a8ef175f7049d->extranet_url = $_d1071a032215f0eb5c4a8ef175f7049d->extranet_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_bf2063735d11aa24bb98d039e" . "b8aeeda"], [$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["extran" . "et_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["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_3c57ea5b" . "6da2c9369" . "336cdba5b" . "9ccf1a"], [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["user" . "_id"] => $_9a2ef4ae6a5745ffe5fac33c88a222fa->admin_id]) : null;
        $_9a2ef4ae6a5745ffe5fac33c88a222fa->groups_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_f241e378ff0d5578f1d346303" . "ac4aaef"], [$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["extranet" . "_id"] => $_9a2ef4ae6a5745ffe5fac33c88a222fa->id]);
        $_9a2ef4ae6a5745ffe5fac33c88a222fa->roles_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_b9aada43a43a79c" . "46a1fe6be5480263" . "9"], [$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["extra" . "net_i" . "d"] => $_9a2ef4ae6a5745ffe5fac33c88a222fa->id]);
        $_9a2ef4ae6a5745ffe5fac33c88a222fa->users_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_707bfdcf1b1350e184bf72" . "73b2cf1602"], [$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["ext" . "ran" . "et_" . "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["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_ba3845cb79c005cf3269af8c" . "83ddbe5e"] => true, $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["st" . "at" . "us"] => StatusCode::BAD_REQUEST, $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["messag" . "e"] => $exception->getMessage(), $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_c78f29e7b113c7a4d2" . "9fe3c4468181e9"] => $exception->getValidationErrors()];
        return new JsonPrettyResponse($data, StatusCode::BAD_REQUEST);
    }
    
    
    
    
    
    
    
    public function FormatPermissionException(PermissionException $exception) : JsonPrettyResponse
    {
        $data = [$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_ba3845cb79c005cf" . "3269af8c83ddbe5e"] => true, $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["sta" . "tus"] => StatusCode::FORBIDDEN, $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["messa" . "ge"] => $exception->getMessage(), $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_c78f29e7b113c7a4d29fe3c4468181e" . "9"] => $exception->getErrors()];
        return new JsonPrettyResponse($data, StatusCode::FORBIDDEN);
    }
}