<?php
namespace Claromentis\Projects\Controller\Rest;

$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"] = (@$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"] ?: array()) + array("_c894747360c6ec5bd8169530ea" . "f9c473" => base64_decode("QmFkIFJlcXVlc" . "3Q="), "_f4afc0b7" . "f4289969a" . "a2dc51007" . "28731f" => base64_decode("cHJvamVjdHMucmVzdC5ub1" . "9wcm9qZWN0"));
use Claromentis\Core\Http\JsonPrettyResponse;
use Claromentis\Core\Http\ResponseFactory;
use Claromentis\Core\Localization\Lmsg;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\Projects\Filter\ProjectRestFilter;
use Claromentis\Projects\Permissions;
use Claromentis\Projects\PermissionsChecker;
use Claromentis\Projects\ProjectListFilter;
use Claromentis\Projects\Repository\ProjectRepository;
use Claromentis\Projects\RestFormatter;
use Psr\Http\Message\ServerRequestInterface;
class ProjectController
{
    private RestFormatter $formatter;
    private ResponseFactory $response;
    private ProjectRepository $repo;
    private PermissionsChecker $permissions;
    private Lmsg $lmsg;
    public function __construct(RestFormatter $formatter, ResponseFactory $response, ProjectRepository $repo, PermissionsChecker $permissions, Lmsg $lmsg)
    {
        $this->formatter = $formatter;
        $this->response = $response;
        $this->repo = $repo;
        $this->permissions = $permissions;
        $this->lmsg = $lmsg;
    }
    public function getProjects(ServerRequestInterface $_b791059c94b285cdf1c90ca6f3a8f2a6, SecurityContext $context) : JsonPrettyResponse
    {
        $_03e9164d0a343b742df4793268b80767 = new ProjectRestFilter(new ProjectListFilter());
        try {
            $_03e9164d0a343b742df4793268b80767->fill($_b791059c94b285cdf1c90ca6f3a8f2a6);
        } catch (\InvalidArgumentException $_c35473364fa7a050299058f332ec29c1) {
            throw new \RestExBadRequest($_c35473364fa7a050299058f332ec29c1->getMessage(), $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_c89474736" . "0c6ec5bd81" . "69530eaf9c" . "473"], $_c35473364fa7a050299058f332ec29c1);
        }
        $this->repo->SetListFilter($_03e9164d0a343b742df4793268b80767->getListFilter());
        $_68680c984182bf7876b2bb0ab77ebe01 = $this->repo->GetProjects(true);
        $_f4eafa5f493306ffdb51a688b21dd507 = $this->repo->GetProjectCount();
        return $this->response->GetJsonPrettyResponse($this->formatter->Paginate($_b791059c94b285cdf1c90ca6f3a8f2a6, $this->formatter->formatProjects($_68680c984182bf7876b2bb0ab77ebe01), $_03e9164d0a343b742df4793268b80767->getChanged(), $_f4eafa5f493306ffdb51a688b21dd507));
    }
    public function getProject(SecurityContext $context, int $project_id) : JsonPrettyResponse
    {
        if (!$this->permissions->CanI($project_id, Permissions::VIEW_PROJECT)) {
            throw new \RestExNotFound(($this->lmsg)($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_f4afc0b" . "7f428996" . "9aa2dc51" . "00728731" . "f"]));
        }
        $project = $this->repo->GetProject($project_id);
        if (!$project) {
            throw new \RestExNotFound(($this->lmsg)($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_f4afc0b7f4289969aa2dc510" . "0728731f"]));
        }
        return $this->response->GetJsonPrettyResponse($this->formatter->formatProject($project));
    }
}