<?php
namespace Claromentis\People;

$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"] ?: array()) + array("_c78f29e7b113c7a4d29fe3c446818" . "1e9" => base64_decode("ZXJyb3" . "Jz"), "_b9aada43a43a79c46a1fe" . "6be54802639" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X" . "3JvbGVz"), "_f241e378ff0d5578f1d34630" . "3ac4aaef" => base64_decode("cGVvcGxlLnJlc3QuZ2V0" . "X2dyb3Vwcw=="), "_707bfdcf1b1350e184bf7273b" . "2cf1602" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X" . "2V4dHJhbmV0X3VzZXJz"), "_17bccc635eff9" . "10e2579ec983b8" . "2869e" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X3J" . "vbGVfdXNlcnM="), "_bf2063735d11aa24bb98d039e" . "b8aeeda" => base64_decode("cGVvcGxlLnJl" . "c3QuZ2V0X2V4" . "dHJhbmV0"), "_c9a58ab51fadf2ed15b0d0ce8a09e50" . "6" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X3" . "VzZXJfc3Vib3JkaW5hdGVz"), "stat" . "us" => base64_decode("c3RhdHV" . "z"), "_326521a4b3c8a9c8b" . "77634f1f44b3e5a" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X2" . "dyb3Vw"), "_4d707fab93be" . "bb00bbe69e815" . "9697c90" => base64_decode(""), "user_i" . "d" => base64_decode("dXNlcl9p" . "ZA=="), "role_i" . "d" => base64_decode("cm9sZV" . "9pZA=="), "gro" . "up_" . "id" => base64_decode("Z3J" . "vdX" . "Bfa" . "WQ="), "extran" . "et_id" => base64_decode("ZXh0cmFuZ" . "XRfaWQ="), "messa" . "ge" => base64_decode("bWVzc2FnZQ" . "=="), "_3c57ea5b6da2c" . "9369336cdba5b9" . "ccf1a" => base64_decode("cGVvcGxlLnJlc3" . "QuZ2V0X3VzZXI="), "_8b281d2a39e2" . "069eea1195ce9" . "42083ca" => base64_decode("cGVvcGxlLnJlc3QuZ2V0" . "X2dyb3VwX3VzZXJz"), "_4efca57498a2951578bf2e1" . "ba92d64d7" => base64_decode("cGVvcGxlLnJlc3QuZ2V0X3VzZXJ" . "fZ3JvdXBz"), "_ba3845cb79c005cf3269af8c83ddbe" . "5e" => base64_decode("ZXJyb3" . "I="), "par" . "ent" . "_id" => base64_decode("cGFyZW5" . "0X2lk"), "_fc9d7314a9d9958d8fa0a" . "403ba8ff197" => base64_decode("Z2V0X2NsYXN" . "z"), "_ece5dd81572732c3e" . "2866ce42bb75431" => base64_decode("cGVvcGxlLnJlc3QuZ2V0" . "X3VzZXJfcm9sZXM="));
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["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["user" . "_id"] => $_24e0e36600d6af77406a44bb618a6253->id];
        
        
        $_24e0e36600d6af77406a44bb618a6253->subordinates_url = $this->GenerateUrl($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_c9a58ab51fadf2ed15b0d0" . "ce8a09e506"], $_3c76edc0804ad93f2e140288dfafba27);
        
        
        
        
        
        
        if ($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_fc9d7314a9d9958d8fa0a403ba8" . "ff197"]($_24e0e36600d6af77406a44bb618a6253->extranet) == Extranet::class) {
            $_24e0e36600d6af77406a44bb618a6253->extranet_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_bf2063735d11aa24b" . "b98d039eb8aeeda"], [$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["extran" . "et_id"] => $_24e0e36600d6af77406a44bb618a6253->extranet->id]);
        } else {
            $_24e0e36600d6af77406a44bb618a6253->extranet_url = $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_4d707fab93bebb00" . "bbe69e8159697c90"];
        }
        $_24e0e36600d6af77406a44bb618a6253->groups_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_4efca57498a295157" . "8bf2e1ba92d64d7"], $_3c76edc0804ad93f2e140288dfafba27);
        $_24e0e36600d6af77406a44bb618a6253->roles_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_ece5dd81572732c3e2866ce42bb754" . "31"], $_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["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_326521a4b3c8a9c8b7" . "7634f1f44b3e5a"], [$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["group_" . "id"] => $_e9208e4fb555ac989f7519e19c1da810->parent_id]) : null;
        $_e9208e4fb555ac989f7519e19c1da810->owner_url = $_e9208e4fb555ac989f7519e19c1da810->owner_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_3c57ea5" . "b6da2c93" . "69336cdb" . "a5b9ccf1" . "a"], [$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["user" . "_id"] => $_e9208e4fb555ac989f7519e19c1da810->owner_id]) : null;
        $_e9208e4fb555ac989f7519e19c1da810->extranet_url = $_e9208e4fb555ac989f7519e19c1da810->extranet_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_bf2063735d11a" . "a24bb98d039eb8" . "aeeda"], [$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["extr" . "anet" . "_id"] => $_e9208e4fb555ac989f7519e19c1da810->extranet_id]) : null;
        $_e9208e4fb555ac989f7519e19c1da810->users_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_8b281d2a39e2069eea" . "1195ce942083ca"], [$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["group_" . "id"] => $_e9208e4fb555ac989f7519e19c1da810->id]);
        $_e9208e4fb555ac989f7519e19c1da810->subgroups_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_f241e378ff0d5578f1d346303ac4" . "aaef"], [$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["parent_" . "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["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_17bccc635eff910e25" . "79ec983b82869e"], [$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["role_i" . "d"] => $_d1071a032215f0eb5c4a8ef175f7049d->id]);
        $_d1071a032215f0eb5c4a8ef175f7049d->owner_url = $_d1071a032215f0eb5c4a8ef175f7049d->owner_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_3c57ea5b6da2c936" . "9336cdba5b9ccf1a"], [$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["user" . "_id"] => $_d1071a032215f0eb5c4a8ef175f7049d->owner_id]) : null;
        $_d1071a032215f0eb5c4a8ef175f7049d->extranet_url = $_d1071a032215f0eb5c4a8ef175f7049d->extranet_id ? $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_bf2063735d11aa24bb98d039" . "eb8aeeda"], [$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["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["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_3c57ea5b6" . "da2c936933" . "6cdba5b9cc" . "f1a"], [$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["user" . "_id"] => $_9a2ef4ae6a5745ffe5fac33c88a222fa->admin_id]) : null;
        $_9a2ef4ae6a5745ffe5fac33c88a222fa->groups_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_f241e378ff0d5578f1d3" . "46303ac4aaef"], [$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["extranet_" . "id"] => $_9a2ef4ae6a5745ffe5fac33c88a222fa->id]);
        $_9a2ef4ae6a5745ffe5fac33c88a222fa->roles_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_b9aada43a" . "43a79c46a1" . "fe6be54802" . "639"], [$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["extrane" . "t_id"] => $_9a2ef4ae6a5745ffe5fac33c88a222fa->id]);
        $_9a2ef4ae6a5745ffe5fac33c88a222fa->users_url = $this->GenerateUrl($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_707bfdcf1b1350e184bf" . "7273b2cf1602"], [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["extranet" . "_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["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_ba3845cb79c005cf3269af" . "8c83ddbe5e"] => true, $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["st" . "at" . "us"] => StatusCode::BAD_REQUEST, $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["me" . "ss" . "ag" . "e"] => $exception->getMessage(), $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_c78f29e7b113c7a4d29fe3c4468181e" . "9"] => $exception->getValidationErrors()];
        return new JsonPrettyResponse($data, StatusCode::BAD_REQUEST);
    }
    
    
    
    
    
    
    
    public function FormatPermissionException(PermissionException $exception) : JsonPrettyResponse
    {
        $data = [$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_ba3845cb79c005cf3269af8c83d" . "dbe5e"] => true, $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["st" . "at" . "us"] => StatusCode::FORBIDDEN, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["messag" . "e"] => $exception->getMessage(), $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_c78f29e7b113c7a4d29fe3c44681" . "81e9"] => $exception->getErrors()];
        return new JsonPrettyResponse($data, StatusCode::FORBIDDEN);
    }
}