<?php
namespace Claromentis\People;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"] ?: array()) + array("_3c57ea5b6da2c936933" . "6cdba5b9ccf1a" => base64_decode("cGVvcGxlLnJlc3QuZ" . "2V0X3VzZXI="), "_c78f29e7b113c7a4d29fe3c4" . "468181e9" => base64_decode("ZXJyb3" . "Jz"), "_707bfdcf1b13" . "50e184bf7273b" . "2cf1602" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X2V4dHJhbmV0X3VzZX" . "Jz"), "group_" . "id" => base64_decode("Z3JvdXBfaW" . "Q="), "_f241e378ff0d5578f1d346303a" . "c4aaef" => base64_decode("cGVvcGxlLnJlc3Q" . "uZ2V0X2dyb3Vwcw" . "=="), "_ba3845cb79c005cf3269af8c83" . "ddbe5e" => base64_decode("ZXJy" . "b3I="), "_17bccc635eff91" . "0e2579ec983b828" . "69e" => base64_decode("cGVvcGxlLnJl" . "c3QuZ2V0X3Jv" . "bGVfdXNlcnM="), "me" . "ss" . "ag" . "e" => base64_decode("bWVzc2Fn" . "ZQ=="), "_4efca57498a2951578bf2" . "e1ba92d64d7" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X3V" . "zZXJfZ3JvdXBz"), "_326521a4b3c8a9c8b77634f" . "1f44b3e5a" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X2dyb3V" . "w"), "extran" . "et_id" => base64_decode("ZXh0cmFuZXR" . "faWQ="), "_bf2063735d11aa24bb98d" . "039eb8aeeda" => base64_decode("cGVvcGxlLnJlc3Qu" . "Z2V0X2V4dHJhbmV0"), "user_" . "id" => base64_decode("dXNlcl9pZA" . "=="), "role" . "_id" => base64_decode("cm9sZ" . "V9pZA" . "=="), "_ece5dd81572732c3e2866ce4" . "2bb75431" => base64_decode("cGVvcGxlLnJlc3QuZ2V0" . "X3VzZXJfcm9sZXM="), "_8b281d2a39e2069" . "eea1195ce942083c" . "a" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X2dyb3VwX3VzZXJ" . "z"), "_b9aada43a43a79c46" . "a1fe6be54802639" => base64_decode("cGVvcGx" . "lLnJlc3" . "QuZ2V0X" . "3JvbGVz"), "_4d707fab93" . "bebb00bbe69" . "e8159697c90" => base64_decode(""), "_fc9d7314a9d9958d8fa" . "0a403ba8ff197" => base64_decode("Z2V0X2N" . "sYXNz"), "st" . "at" . "us" => base64_decode("c3RhdHV" . "z"), "paren" . "t_id" => base64_decode("cGFyZW5" . "0X2lk"), "_c9a58ab51f" . "adf2ed15b0d" . "0ce8a09e506" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X3VzZXJfc3Vib3JkaW5hdGV" . "z"));
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["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["user_" . "id"] => $_24e0e36600d6af77406a44bb618a6253->id];
        
        
        $_24e0e36600d6af77406a44bb618a6253->subordinates_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_c9a58ab51fadf2ed15b0d0c" . "e8a09e506"], $_3c76edc0804ad93f2e140288dfafba27);
        
        
        
        
        
        
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_fc9d7314a9d9958d8fa0a403ba" . "8ff197"]($_24e0e36600d6af77406a44bb618a6253->extranet) == Extranet::class) {
            $_24e0e36600d6af77406a44bb618a6253->extranet_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_bf2063735d11" . "aa24bb98d039e" . "b8aeeda"], [$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["extranet" . "_id"] => $_24e0e36600d6af77406a44bb618a6253->extranet->id]);
        } else {
            $_24e0e36600d6af77406a44bb618a6253->extranet_url = $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_4d707fab93bebb00bbe69e81596" . "97c90"];
        }
        $_24e0e36600d6af77406a44bb618a6253->groups_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_4efca57498a2951578bf2e1b" . "a92d64d7"], $_3c76edc0804ad93f2e140288dfafba27);
        $_24e0e36600d6af77406a44bb618a6253->roles_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_ece5dd81572732c3e2" . "866ce42bb75431"], $_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["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_326521a4b3c8a9c8b7" . "7634f1f44b3e5a"], [$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["grou" . "p_id"] => $_e9208e4fb555ac989f7519e19c1da810->parent_id]) : null;
        $_e9208e4fb555ac989f7519e19c1da810->owner_url = $_e9208e4fb555ac989f7519e19c1da810->owner_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_3c57ea5b6da2c9369336cdb" . "a5b9ccf1a"], [$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["user_" . "id"] => $_e9208e4fb555ac989f7519e19c1da810->owner_id]) : null;
        $_e9208e4fb555ac989f7519e19c1da810->extranet_url = $_e9208e4fb555ac989f7519e19c1da810->extranet_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_bf2063735d11aa24bb98d03" . "9eb8aeeda"], [$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["extra" . "net_i" . "d"] => $_e9208e4fb555ac989f7519e19c1da810->extranet_id]) : null;
        $_e9208e4fb555ac989f7519e19c1da810->users_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_8b281d2a39e20" . "69eea1195ce942" . "083ca"], [$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["group_i" . "d"] => $_e9208e4fb555ac989f7519e19c1da810->id]);
        $_e9208e4fb555ac989f7519e19c1da810->subgroups_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_f241e378ff0d55" . "78f1d346303ac4a" . "aef"], [$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["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["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_17bccc635eff910e2579ec9" . "83b82869e"], [$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["role_i" . "d"] => $_d1071a032215f0eb5c4a8ef175f7049d->id]);
        $_d1071a032215f0eb5c4a8ef175f7049d->owner_url = $_d1071a032215f0eb5c4a8ef175f7049d->owner_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_3c57ea5b6da2c9369336cdb" . "a5b9ccf1a"], [$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["user_i" . "d"] => $_d1071a032215f0eb5c4a8ef175f7049d->owner_id]) : null;
        $_d1071a032215f0eb5c4a8ef175f7049d->extranet_url = $_d1071a032215f0eb5c4a8ef175f7049d->extranet_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_bf2063735d11aa24bb98d039eb8ae" . "eda"], [$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["extranet_" . "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["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_3c57ea5" . "b6da2c93" . "69336cdb" . "a5b9ccf1" . "a"], [$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["us" . "er" . "_i" . "d"] => $_9a2ef4ae6a5745ffe5fac33c88a222fa->admin_id]) : null;
        $_9a2ef4ae6a5745ffe5fac33c88a222fa->groups_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_f241e378ff0d5578f1d346303ac4" . "aaef"], [$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["extr" . "anet" . "_id"] => $_9a2ef4ae6a5745ffe5fac33c88a222fa->id]);
        $_9a2ef4ae6a5745ffe5fac33c88a222fa->roles_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_b9aada43a4" . "3a79c46a1fe" . "6be54802639"], [$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["extranet_" . "id"] => $_9a2ef4ae6a5745ffe5fac33c88a222fa->id]);
        $_9a2ef4ae6a5745ffe5fac33c88a222fa->users_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_707bfdcf1b1" . "350e184bf727" . "3b2cf1602"], [$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["extranet_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["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_ba3845cb79" . "c005cf3269a" . "f8c83ddbe5e"] => true, $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["statu" . "s"] => StatusCode::BAD_REQUEST, $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["me" . "ss" . "ag" . "e"] => $exception->getMessage(), $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_c78f29e7b113c7a4d29fe3" . "c4468181e9"] => $exception->getValidationErrors()];
        return new JsonPrettyResponse($data, StatusCode::BAD_REQUEST);
    }
    
    
    
    
    
    
    
    public function FormatPermissionException(PermissionException $exception) : JsonPrettyResponse
    {
        $data = [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_ba3845cb79c005cf3269af8c83ddbe5" . "e"] => true, $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["stat" . "us"] => StatusCode::FORBIDDEN, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["me" . "ss" . "ag" . "e"] => $exception->getMessage(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_c78f29e7b" . "113c7a4d29" . "fe3c446818" . "1e9"] => $exception->getErrors()];
        return new JsonPrettyResponse($data, StatusCode::FORBIDDEN);
    }
}