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

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"] = (@$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"] ?: array()) + array("_f76b20cae22026c" . "8464c78243696de9" . "7" => base64_decode("aW5mb2NhcHR1cmUucmVz" . "dC5ub19wcm9qZWN0"), "project_i" . "d" => base64_decode("cHJvam" . "VjdF9p" . "ZA=="), "_620d0bf67b054ba2ec0" . "f2fe084782152" => base64_decode("aW5mb2NhcHR1cmU" . "ucmVzdC5ub19wZX" . "JtaXNzaW9uX2lzc" . "3Vl"), "_a4a101825" . "8adabb74e7" . "b04836d8d7" . "e3b" => base64_decode("Tm90IEZ" . "vdW5k"), "_713b5bcf16665bcb3ed9" . "28c7b52838d8" => base64_decode("VW5leHBlY3RlZCBlcn" . "Jvcg=="), "_c05f8f22b90692" . "278db70d3c30471" . "1e5" => base64_decode("aW5mb2NhcHR1cmUucmVzd" . "C5ub19wZXJtaXNzaW9uX3" . "Byb2plY3Q="), "_5b40f7ef8f96b73095c82ad1" . "b60eabbe" => base64_decode("aW5mb2NhcHR1cmUucmVzdC5ub19pc3N1" . "ZQ=="), "_3efc5ba7bf51ca70907f5e65ab602" . "ec1" => base64_decode("SW50ZXJuYWwgU2V" . "ydmVyIEVycm9y"), "_79bd87060993ff622ef212c1e8b" . "6a79a" => base64_decode("Rm9yYml" . "kZGVu"));
use Claromentis\Core\Audit\Audit;
use Claromentis\Core\Http\JsonPrettyResponse;
use Claromentis\Core\Http\ResponseFactory;
use Claromentis\Core\Localization\Lmsg;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\Infocapture\Api;
use Claromentis\Infocapture\Exception\NotFoundException;
use Claromentis\Infocapture\Exception\PermissionException;
use Claromentis\Infocapture\Filter\IssueFilter;
use Claromentis\Infocapture\RestFormatter;
use Psr\Http\Message\ServerRequestInterface;
class IssueController
{
    protected RestFormatter $formatter;
    protected ResponseFactory $response;
    protected Api $api;
    protected Lmsg $lmsg;
    protected Audit $audit;
    public function __construct(RestFormatter $formatter, ResponseFactory $response, Api $api, Lmsg $lmsg)
    {
        $this->formatter = $formatter;
        $this->response = $response;
        $this->api = $api;
        $this->lmsg = $lmsg;
    }
    
    
    
    
    
    
    
    
    
    
    
    public function getIssue(SecurityContext $context, int $issueId) : JsonPrettyResponse
    {
        try {
            $issue = $this->api->getIssue($context, $issueId);
            $project = $this->api->getProject($context, $issue->GetProperty($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["project_" . "id"]));
            $this->api->loadHistoryForIssues($context, [$issue]);
            $_69060fd98946c48b106c3cfed6f233a7 = $this->formatter->FormatIssue($context, $project, $issue);
        } catch (PermissionException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            throw new \RestExForbidden(($this->lmsg)($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_620d0bf67b054b" . "a2ec0f2fe084782" . "152"]), $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_79bd8706" . "0993ff622" . "ef212c1e8" . "b6a79a"], $_fe441aa3ef350bfb1a1a1ad8520dd530);
        } catch (NotFoundException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            throw new \RestExNotFound(($this->lmsg)($GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_5b40f7ef8f96b73095c82a" . "d1b60eabbe"]), $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_a4a1018258ad" . "abb74e7b04836" . "d8d7e3b"], $_fe441aa3ef350bfb1a1a1ad8520dd530);
        } catch (\Throwable $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            throw new \RestExError($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_713b5bcf16665bcb3ed928c7" . "b52838d8"], 500, $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_3efc5ba7" . "bf51ca709" . "07f5e65ab" . "602ec1"], $_fe441aa3ef350bfb1a1a1ad8520dd530);
        }
        return $this->response->GetJsonPrettyResponse($_69060fd98946c48b106c3cfed6f233a7);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    public function getProjectIssue(SecurityContext $context, int $projectId, int $issueIid) : JsonPrettyResponse
    {
        try {
            $issue = $this->api->getProjectIssue($context, $projectId, $issueIid);
            $project = $this->api->getProject($context, $issue->GetProperty($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["project" . "_id"]));
            $this->api->loadHistoryForIssues($context, [$issue]);
            $_69060fd98946c48b106c3cfed6f233a7 = $this->formatter->FormatIssue($context, $project, $issue);
        } catch (PermissionException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            throw new \RestExForbidden(($this->lmsg)($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_620d0bf6" . "7b054ba2e" . "c0f2fe084" . "782152"]), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_79bd87060993ff622ef212c1e8b6" . "a79a"], $_fe441aa3ef350bfb1a1a1ad8520dd530);
        } catch (NotFoundException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            throw new \RestExNotFound(($this->lmsg)($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_5b40f7ef8f96b73095c82ad" . "1b60eabbe"]), $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_a4a1018258adabb74e7b" . "04836d8d7e3b"], $_fe441aa3ef350bfb1a1a1ad8520dd530);
        } catch (\Throwable $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            throw new \RestExError($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_713b5bcf16665b" . "cb3ed928c7b5283" . "8d8"], 500, $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_3efc5ba" . "7bf51ca7" . "0907f5e6" . "5ab602ec" . "1"], $_fe441aa3ef350bfb1a1a1ad8520dd530);
        }
        return $this->response->GetJsonPrettyResponse($_69060fd98946c48b106c3cfed6f233a7);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function getIssues(ServerRequestInterface $request, SecurityContext $context, ?int $projectId = null) : JsonPrettyResponse
    {
        $_03e9164d0a343b742df4793268b80767 = new IssueFilter();
        $_03e9164d0a343b742df4793268b80767->setProjectId($projectId);
        $_03e9164d0a343b742df4793268b80767->fill($request);
        try {
            $_a020ae3bf420cc88a5518a5ff484ac6f = $this->api->getIssues($context, $_03e9164d0a343b742df4793268b80767);
            $_6c561ef3cab8b84b15653472f877643e = $this->api->getIssuesCount($context, $_03e9164d0a343b742df4793268b80767);
            $this->api->loadHistoryForIssues($context, $_a020ae3bf420cc88a5518a5ff484ac6f);
            $_7fa7c4fca4fac915f0ab1ef667084a04 = $_03e9164d0a343b742df4793268b80767->toArray();
            unset($_7fa7c4fca4fac915f0ab1ef667084a04[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["projec" . "t_id"]]);
            $response = $this->formatter->Paginate($request, $this->formatter->FormatIssues($context, $_a020ae3bf420cc88a5518a5ff484ac6f), $_7fa7c4fca4fac915f0ab1ef667084a04, $_6c561ef3cab8b84b15653472f877643e);
        } catch (PermissionException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            throw new \RestExForbidden(($this->lmsg)($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_c05f8f22" . "b90692278" . "db70d3c30" . "4711e5"]), $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_79bd870609" . "93ff622ef21" . "2c1e8b6a79a"], $_fe441aa3ef350bfb1a1a1ad8520dd530);
        } catch (NotFoundException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            throw new \RestExNotFound(($this->lmsg)($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_f76b20c" . "ae22026c" . "8464c782" . "43696de9" . "7"]), $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_a4a1018258adabb74e7b04836d8d7e" . "3b"], $_fe441aa3ef350bfb1a1a1ad8520dd530);
        } catch (\Throwable $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            throw new \RestExError($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_713b5bcf16665bcb3ed928c7b" . "52838d8"], 500, $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_3efc5ba7bf51ca" . "70907f5e65ab602" . "ec1"], $_fe441aa3ef350bfb1a1a1ad8520dd530);
        }
        return $this->response->GetJsonPrettyResponse($response);
    }
}