<?php
namespace Claromentis\Projects\Controller;

$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"] = (@$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"] ?: array()) + array("_0ea4e32b57963a" . "c0cb3057e03e9ae" . "f64" => base64_decode("a" . "W" . "Q" . "="), "_f33594668a14" . "ecd5ede1fb90b" . "8354c70" => base64_decode("TmV3IHN0YXR1cyBtdXN0IG" . "hhdmUgbmFtZQ=="), "_80f432640c97e2aa41266" . "4c408f72221" => base64_decode("Q2Fubm90IGRlbGV0ZSBpbml0aWFs" . "IHN0YXR1cw=="), "_068ab9b9340314c5b07e3e5cc31" . "d925b" => base64_decode("c29ydF" . "9vcmRl" . "cg=="), "st" . "at" . "us" => base64_decode("c3RhdH" . "Vz"), "st" . "at" . "us" . "es" => base64_decode("c3Rhd" . "HVzZX" . "M="), "_8dabb06ef" . "c95df4cff7" . "c4afe91857" . "b53" => base64_decode("bmF" . "tZQ" . "=="), "_a29b27c98290e926d8b084b" . "48c9ce369" => base64_decode("WW91IGRvIG5vdCBoYXZlIHBlcm1pc3Npb" . "24gdG8gZWRpdCB0aGUgbGlzdCBvZiBzdG" . "F0dXNlcw=="), "_4d23892ff91aa3195a85bb" . "548a7f4333" => base64_decode("bG9jYWxpemVkX25h" . "bWU="), "_7d5f0a31f61b7b734f21a9bf6acf25" . "02" => base64_decode("Q2Fubm90IGRlbGV0ZSBmaW5" . "hbCBzdGF0dXM="), "_9ed84d2923d81db75e6348d1b290c0" . "51" => base64_decode("Y29tcGxldGVkX3N0" . "YXR1c19sYWJlbA=="), "_5f4d1ad89c9" . "41500471a837" . "0398dad9e" => base64_decode("dG9kb19zdGF0dXNfbG" . "FiZWw="), "_8f4004bb39963606d042524cafb" . "2c56e" => base64_decode("Tm8gbmFtZSBnaXZl" . "bg=="), "_f4afc0b7f4289969aa2dc51" . "00728731f" => base64_decode("cHJvamVjdHMucmVzdC5ub19w" . "cm9qZWN0"), "_f805302e3f25df291a3" . "dd8ea386da8a4" => base64_decode("IGluIHByb2" . "plY3Qg"), "_b94c0530a0fc194" . "21865e1efa5f6779" . "f" => base64_decode("Tm8gc3RhdHVzIEl" . "EIA=="));
use Analogue\ORM\Exceptions\MappingException;
use Claromentis\Core\CDN;
use Claromentis\Core\Http\JsonPrettyResponse;
use Claromentis\Core\Localization\Lmsg;
use Claromentis\Core\REST\RestFormatter;
use Claromentis\Projects\Entity\TaskStatus;
use Claromentis\Projects\Exceptions\StatusStorageException;
use Claromentis\Projects\Model\Task;
use Claromentis\Projects\Permissions;
use Claromentis\Projects\PermissionsChecker;
use Claromentis\Projects\Repository\ProjectRepository;
use Claromentis\Projects\TaskStatusApi;
use Psr\Http\Message\ServerRequestInterface;
class TaskStatusController
{
    
    
    
    
    protected $api;
    
    
    
    
    protected $project_provider;
    
    
    
    
    protected $formatter;
    
    
    
    
    protected $lmsg;
    public function __construct(TaskStatusApi $api, ProjectRepository $project_provider, RestFormatter $formatter, Lmsg $lmsg)
    {
        $this->api = $api;
        $this->project_provider = $project_provider;
        $this->formatter = $formatter;
        $this->lmsg = $lmsg;
    }
    
    
    
    
    
    
    
    
    public function ShowList(int $project_id) : JsonPrettyResponse
    {
        $project = $this->project_provider->GetProject($project_id);
        if (!$project) {
            throw new \RestExNotFound(($this->lmsg)($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_f4afc0b7f4289969aa2" . "dc5100728731f"]));
        }
        $statuses = $this->api->getProjectStatuses($project)->all();
        return new JsonPrettyResponse([[$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["statu" . "ses"] => $this->FormatStatuses($statuses)]]);
    }
    
    
    
    
    
    
    
    
    
    public function Show(int $project_id, TaskStatus $status) : JsonPrettyResponse
    {
        $this->CheckProjectId($project_id, $status);
        return new JsonPrettyResponse([$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["sta" . "tus"] => $this->FormatStatus($status)]);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function Update(int $project_id, TaskStatus $status, ServerRequestInterface $_b791059c94b285cdf1c90ca6f3a8f2a6, PermissionsChecker $permissions_checker) : JsonPrettyResponse
    {
        $this->CheckProjectId($project_id, $status);
        $this->CheckEditPermissions($project_id, $permissions_checker);
        $_231341bedbbeea0ba9fa8da63ef63dc1 = $status->id === 0;
        $_a71dc9333bd8ad95d55d6624b477875f = $this->formatter->GetJson($_b791059c94b285cdf1c90ca6f3a8f2a6);
        $_9bacb470d4f91e74f3caafec23aeca8e = clone $status;
        if ($_231341bedbbeea0ba9fa8da63ef63dc1) {
            $status->project_id = $project_id;
            if (empty($_a71dc9333bd8ad95d55d6624b477875f[$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_8dabb06efc95df4" . "cff7c4afe91857b5" . "3"]])) {
                throw new \RestExBadRequest($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_f33594668a14ecd5ede1fb" . "90b8354c70"]);
            }
        }
        $status->sort_order = $_a71dc9333bd8ad95d55d6624b477875f[$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_068ab9b9340314c5" . "b07e3e5cc31d925b"]] ?? $status->sort_order;
        $status->name = $_a71dc9333bd8ad95d55d6624b477875f[$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_8dabb06efc95df4cff7c4afe918" . "57b53"]] ?? $status->name;
        $this->api->SaveStatus($status);
        if ($_231341bedbbeea0ba9fa8da63ef63dc1) {
            $this->api->StatusAddedHistory($status);
        } else {
            $this->api->StatusUpdatedHistory($_9bacb470d4f91e74f3caafec23aeca8e, $status);
        }
        return new JsonPrettyResponse([$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["sta" . "tus"] => $this->FormatStatus($status)], $_231341bedbbeea0ba9fa8da63ef63dc1 ? 201 : 200);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function UpdateV3(int $project_id, TaskStatus $status, ServerRequestInterface $_b791059c94b285cdf1c90ca6f3a8f2a6, PermissionsChecker $permissions_checker) : JsonPrettyResponse
    {
        $this->CheckProjectId($project_id, $status);
        $this->CheckEditPermissions($project_id, $permissions_checker);
        $_231341bedbbeea0ba9fa8da63ef63dc1 = $status->id === 0;
        $_a71dc9333bd8ad95d55d6624b477875f = $this->formatter->GetJson($_b791059c94b285cdf1c90ca6f3a8f2a6);
        $_9bacb470d4f91e74f3caafec23aeca8e = clone $status;
        if ($_231341bedbbeea0ba9fa8da63ef63dc1) {
            $status->project_id = $project_id;
            if (empty($_a71dc9333bd8ad95d55d6624b477875f[$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_8dabb06efc" . "95df4cff7c4" . "afe91857b53"]])) {
                throw new \RestExBadRequest($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_f33594668a14ecd5ede1fb90b" . "8354c70"]);
            }
        }
        $status->sort_order = $_a71dc9333bd8ad95d55d6624b477875f[$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_068ab9b9340314c5b07e3e5cc31d9" . "25b"]] ?? $status->sort_order;
        $status->name = $_a71dc9333bd8ad95d55d6624b477875f[$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_8dabb06efc95df4cff7c4af" . "e91857b53"]] ?? $status->name;
        $this->api->SaveStatus($status);
        if ($_231341bedbbeea0ba9fa8da63ef63dc1) {
            $this->api->StatusAddedHistory($status);
        } else {
            $this->api->StatusUpdatedHistory($_9bacb470d4f91e74f3caafec23aeca8e, $status);
        }
        $_1833c1908972ebd0c77f861e80c2d9bf = $this->api->getProjectStatuses($project_id);
        return new JsonPrettyResponse([$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["statu" . "s"] => $this->FormatStatus($status), $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["statuse" . "s"] => $this->FormatStatuses($_1833c1908972ebd0c77f861e80c2d9bf)], $_231341bedbbeea0ba9fa8da63ef63dc1 ? 201 : 200);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    public function Delete(int $project_id, TaskStatus $status, PermissionsChecker $permissions_checker) : JsonPrettyResponse
    {
        $this->CheckProjectId($project_id, $status);
        $this->CheckEditPermissions($project_id, $permissions_checker);
        $this->api->DeleteStatus($status);
        return new JsonPrettyResponse([$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["st" . "at" . "us"] => $this->FormatStatus($status)]);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function DeleteV3(int $project_id, TaskStatus $status, PermissionsChecker $permissions_checker) : JsonPrettyResponse
    {
        $this->CheckProjectId($project_id, $status);
        $this->CheckEditPermissions($project_id, $permissions_checker);
        $this->api->DeleteStatus($status);
        $_1833c1908972ebd0c77f861e80c2d9bf = $this->api->getProjectStatuses($project_id);
        return new JsonPrettyResponse([$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["stat" . "us"] => $this->FormatStatus($status), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["stat" . "uses"] => $this->FormatStatuses($_1833c1908972ebd0c77f861e80c2d9bf)]);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function UpdateTodo(PermissionsChecker $permissions_checker, int $project_id, ServerRequestInterface $_b791059c94b285cdf1c90ca6f3a8f2a6) : JsonPrettyResponse
    {
        $this->CheckEditPermissions($project_id, $permissions_checker);
        $project = $this->project_provider->GetProject($project_id);
        $_ed5f03d686c37933b5943f295c6b4a43 = $this->formatter->GetJson($_b791059c94b285cdf1c90ca6f3a8f2a6);
        if (!$project) {
            throw new \RestExBadRequest(($this->lmsg)($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_f4afc0b7f4289969a" . "a2dc5100728731f"]));
        }
        if (!isset($_ed5f03d686c37933b5943f295c6b4a43[$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_8dabb06e" . "fc95df4cf" . "f7c4afe91" . "857b53"]])) {
            throw new \RestExBadRequest($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_8f4004bb39963606d0" . "42524cafb2c56e"]);
        }
        $project->SetProperty($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_5f4d1ad89c9415" . "00471a8370398da" . "d9e"], $_ed5f03d686c37933b5943f295c6b4a43[$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_8dabb06efc95df4cff7c4af" . "e91857b53"]]);
        $this->project_provider->SaveProject($project);
        return new JsonPrettyResponse([$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["statu" . "s"] => [$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_0ea4e32b579" . "63ac0cb3057e" . "03e9aef64"] => Task::STATUS_TODO, $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_8dabb06efc95df4cff7c4" . "afe91857b53"] => $_ed5f03d686c37933b5943f295c6b4a43[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_8dabb06efc95df4cff7c4af" . "e91857b53"]], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_4d23892ff91aa3195a85bb" . "548a7f4333"] => $this->lmsg->lmsg_str($_ed5f03d686c37933b5943f295c6b4a43[$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_8dabb06" . "efc95df4" . "cff7c4af" . "e91857b5" . "3"]])]]);
    }
    public function DeleteTodo()
    {
        throw new \RestExBadRequest($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_80f432640c97e2aa41266" . "4c408f72221"]);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function UpdateCompleted(PermissionsChecker $permissions_checker, int $project_id, ServerRequestInterface $_b791059c94b285cdf1c90ca6f3a8f2a6) : JsonPrettyResponse
    {
        $this->CheckEditPermissions($project_id, $permissions_checker);
        $project = $this->project_provider->GetProject($project_id);
        $_ed5f03d686c37933b5943f295c6b4a43 = $this->formatter->GetJson($_b791059c94b285cdf1c90ca6f3a8f2a6);
        if (!$project) {
            throw new \RestExBadRequest(($this->lmsg)($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_f4afc0b7f42899" . "69aa2dc51007287" . "31f"]));
        }
        if (!isset($_ed5f03d686c37933b5943f295c6b4a43[$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_8dabb06" . "efc95df4" . "cff7c4af" . "e91857b5" . "3"]])) {
            throw new \RestExBadRequest($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_8f4004bb399636" . "06d042524cafb2c" . "56e"]);
        }
        $project->SetProperty($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_9ed84d2923d81db75e6348d1b290c" . "051"], $_ed5f03d686c37933b5943f295c6b4a43[$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_8dabb06" . "efc95df4" . "cff7c4af" . "e91857b5" . "3"]]);
        $this->project_provider->SaveProject($project);
        return new JsonPrettyResponse([$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["sta" . "tus"] => [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_0ea4e32b57963ac0cb3057e03e9ae" . "f64"] => Task::STATUS_COMPLETED, $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_8dabb06efc9" . "5df4cff7c4af" . "e91857b53"] => $_ed5f03d686c37933b5943f295c6b4a43[$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_8dabb06ef" . "c95df4cff7" . "c4afe91857" . "b53"]], $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_4d23892ff91aa3195a85bb548a7f43" . "33"] => $this->lmsg->lmsg_str($_ed5f03d686c37933b5943f295c6b4a43[$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_8dabb06efc" . "95df4cff7c4" . "afe91857b53"]])]]);
    }
    public function DeleteCompleted()
    {
        throw new \RestExBadRequest($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_7d5f0a31f61b7b" . "734f21a9bf6acf2" . "502"]);
    }
    
    
    
    
    
    
    
    private function CheckEditPermissions(int $project_id, PermissionsChecker $permissions_checker)
    {
        if (!$permissions_checker->CanI($project_id, Permissions::EDIT_PROJECT_PROPERTIES)) {
            throw new \RestExForbidden($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_a29b27c98290e926" . "d8b084b48c9ce369"]);
        }
    }
    
    
    
    
    
    
    
    private function CheckProjectId(int $project_id, TaskStatus $status)
    {
        if ($status->project_id && $project_id !== $status->project_id) {
            throw new \RestExNotFound($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_b94c0530a0fc19421865e1efa5f677" . "9f"] . $status->id . $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_f805302" . "e3f25df2" . "91a3dd8e" . "a386da8a" . "4"] . $project_id);
        }
    }
    private function FormatStatuses($statuses) : array
    {
        $_e8180e518b009dc0ea8c578fe193c4ae = [];
        
        
        foreach ($statuses as $status) {
            $_e8180e518b009dc0ea8c578fe193c4ae[] = $this->FormatStatus($status);
        }
        return $_e8180e518b009dc0ea8c578fe193c4ae;
    }
    
    
    
    
    
    
    private function FormatStatus(TaskStatus $status) : array
    {
        $status = $status->toArray();
        $status[$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_4d23892ff91aa3195a85bb548" . "a7f4333"]] = $this->lmsg->lmsg_str($status[$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_8dabb06efc95df4cff7" . "c4afe91857b53"]]);
        return $status;
    }
}