<?php
namespace Claromentis\Projects;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"] = (@$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"] ?: array()) + array("_6be7ef0f685c2a96f" . "cae1fc2ccc30198" => base64_decode("Y2h" . "hbm" . "dlc" . "w=="), "_25983d06eff5f52f829961d6" . "bf1a7a70" => base64_decode("bm" . "V3"), "_39055966f" . "5797d95a8c" . "5b326e1928" . "9e6" => base64_decode("cHJvamVjd" . "HMudGFza1" . "9zdGF0dXM" . "uZG9uZQ=="), "_8dabb06efc95df4cff7c4" . "afe91857b53" => base64_decode("bmFtZQ" . "=="), "_52c88622c68f9de6e59b3146dc70" . "9dc5" => base64_decode("c3RhdHVzX2RlbGV0Z" . "WQ="), "_068ab9b9340314c5b" . "07e3e5cc31d925b" => base64_decode("c29ydF9vcmRlc" . "g=="), "_feb9037589181bc30fa0f" . "1cf78b9f056" => base64_decode("dG" . "l0" . "bG" . "U="), "_0c5123aa744f6" . "9bbc0e8b3ea2f6" . "e847d" => base64_decode("bG1z" . "Zw=="), "_5f4d1ad89c941500471" . "a8370398dad9e" => base64_decode("dG9kb19zdGF0dX" . "NfbGFiZWw="), "_dadf790baf241afac9" . "42824c1e6e37c4" => base64_decode("dHlwZ" . "Q=="), "_0ea4e32b57963ac0cb3057e03" . "e9aef64" => base64_decode("aW" . "Q="), "_cb79f297f1fbf9" . "16b9e421a8de7e9" . "b0f" => base64_decode("RmFpbGVkIHRvIHN0b3Jl" . "IGV2ZW50"), "_507a6b14e352bf" . "9974b4646608163" . "e0d" => base64_decode("RmFpbGVkIHRvIGRlbGV0ZSBl" . "dmVudA=="), "_546c50a2" . "525e1b6ee" . "efb4a2ffc" . "ef6833" => base64_decode("c3RhdHVzX3VwZG" . "F0ZWQ="), "_dd981dd316c16a4aca086d9a01ec1ac" . "2" => base64_decode("UHJvamVjdCBhcmd1bWVudCBtdXN0IGJlIHByb2plY3Qgb2JqZWN0" . "IG9yIG51bWVyaWMgcHJvamVjdCBJRA=="), "_9ed84d2923d81db75e6348d1" . "b290c051" => base64_decode("Y29tcGxldG" . "VkX3N0YXR1" . "c19sYWJlbA" . "=="), "me" . "ss" . "ag" . "e" => base64_decode("bWV" . "zc2" . "FnZ" . "Q=="), "_1eb4013342226684733e3" . "c83e4fcff5a" => base64_decode("c3Rhd" . "HVzX2" . "FkZGV" . "k"), "_f0d3cd92e3" . "eb4417d5898" . "658673edaa4" => base64_decode("b2" . "xk"), "_f3378ee2ffbe610a7d" . "709e577c7b3409" => base64_decode("cHJvamVjdH" . "MuaGlzdG9y" . "eS5hcmVhLn" . "Byb2plY3Q="), "_318fb28f101c355b0fc5edf1361d99" . "d8" => base64_decode("cHJvamVjdHMudGFza19" . "zdGF0dXMudG9kbw=="), "_62d701c3c53404f06345eb35720" . "a47b4" => base64_decode("aXNfbnVtZXJpYw" . "=="));
use Claromentis\Core\Event\Event;
use Claromentis\Core\Event\EventDispatcher;
use Claromentis\Core\Event\GenericEvent;
use Claromentis\Core\Localization\Lmsg;
use Claromentis\Core\TextUtil\ClaText;
use Claromentis\Projects\Entity\TaskStatus;
use Claromentis\Projects\Exceptions\StatusStorageException;
use Claromentis\Projects\Model\Project;
use Claromentis\Projects\Model\Task;
use Claromentis\Projects\Repository\ProjectRepository;
use Claromentis\Projects\Repository\TaskStatusRepository;
use Claromentis\Projects\Service\HistoryService;
use UnexpectedValueException;
use Illuminate\Support\Collection;
class TaskStatusApi
{
    
    
    
    
    protected $repository;
    
    
    
    
    protected $project_provider;
    
    
    
    
    protected $dispatcher;
    
    
    protected $history_service;
    
    
    protected $lmsg;
    
    
    protected $text_utils;
    public function __construct(TaskStatusRepository $repository, ProjectRepository $project_provider, EventDispatcher $dispatcher, HistoryService $history_service, Lmsg $lmsg, ClaText $_a07c1768ac6273f9f82dd3c4425e3583)
    {
        $this->repository = $repository;
        $this->project_provider = $project_provider;
        $this->dispatcher = $dispatcher;
        $this->history_service = $history_service;
        $this->lmsg = $lmsg;
        $this->text_utils = $_a07c1768ac6273f9f82dd3c4425e3583;
    }
    public function projectHasStatus($project, int $_d0f9ef06303d1f6bf2691bd0c491726d) : bool
    {
        if ($project instanceof Project) {
            $project = $project->GetId();
        }
        return $this->repository->projectHasStatus((int) $project, $_d0f9ef06303d1f6bf2691bd0c491726d);
    }
    
    
    
    
    
    public function getProjectStatuses($project) : Collection
    {
        if ($project instanceof Project) {
            $project_id = $project->GetId();
        } else {
            $project_id = $project;
            $project = $this->project_provider->GetProject($project_id);
        }
        if (!$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_62d701c3c53404f06345eb35720a4" . "7b4"]($project_id)) {
            throw new UnexpectedValueException($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_dd981dd316c16a4" . "aca086d9a01ec1ac" . "2"]);
        }
        $_ea784b458a82577c4594724dd53f5411 = $project->GetProperty($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_5f4d1ad89c941500471a8370" . "398dad9e"]);
        $_35919829b51e0c4206f415fd49463d5a = $project->GetProperty($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_9ed84d2923d81db75e6348d1b29" . "0c051"]);
        $statuses = $this->repository->getProjectStatuses($project);
        $_6fad12ae02f24de24394588edcdecfd8 = new TaskStatus();
        $_6fad12ae02f24de24394588edcdecfd8->fill([$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_0ea4e32b57963ac0cb3057" . "e03e9aef64"] => Task::STATUS_TODO, $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_8dabb06efc95df4cff7c4afe9185" . "7b53"] => $_ea784b458a82577c4594724dd53f5411, $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_068ab9b9340314c5b07e" . "3e5cc31d925b"] => 0]);
        $_64666bcf1e5aaa07774f3d7439ff264d = new TaskStatus();
        $_64666bcf1e5aaa07774f3d7439ff264d->fill([$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_0ea4e32b57963ac0cb3057e03e9a" . "ef64"] => Task::STATUS_COMPLETED, $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_8dabb06efc95df4" . "cff7c4afe91857b5" . "3"] => $_35919829b51e0c4206f415fd49463d5a, $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_068ab9b934" . "0314c5b07e3" . "e5cc31d925b"] => 9001]);
        $statuses->push($_64666bcf1e5aaa07774f3d7439ff264d);
        $statuses->splice(0, 0, [$_6fad12ae02f24de24394588edcdecfd8]);
        return $statuses;
    }
    public function GetAdHocStatuses()
    {
        $_6fad12ae02f24de24394588edcdecfd8 = new TaskStatus();
        $_6fad12ae02f24de24394588edcdecfd8->fill([$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_0ea4e32b57963" . "ac0cb3057e03e9" . "aef64"] => Task::STATUS_TODO, $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_8dabb06efc95df4cff7c4afe" . "91857b53"] => $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_0c5123aa744f69bbc0e8b" . "3ea2f6e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_318fb28f101" . "c355b0fc5edf" . "1361d99d8"]), $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_068ab9b9" . "340314c5b" . "07e3e5cc3" . "1d925b"] => 0]);
        $_64666bcf1e5aaa07774f3d7439ff264d = new TaskStatus();
        $_64666bcf1e5aaa07774f3d7439ff264d->fill([$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_0ea4e32b57963ac0cb3057e03" . "e9aef64"] => Task::STATUS_COMPLETED, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_8dabb06efc95df4cff7c4afe9185" . "7b53"] => $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_0c5123aa744f69bbc0e8b3ea2f6e847" . "d"]($GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_39055966f5797d95a8c5b3" . "26e19289e6"]), $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_068ab9b9340314" . "c5b07e3e5cc31d9" . "25b"] => 9001]);
        return [$_6fad12ae02f24de24394588edcdecfd8, $_64666bcf1e5aaa07774f3d7439ff264d];
    }
    public function GetStatus(int $_0ea4e32b57963ac0cb3057e03e9aef64) : ?TaskStatus
    {
        return $this->repository->find($_0ea4e32b57963ac0cb3057e03e9aef64);
    }
    
    
    
    
    
    
    public function SaveStatus(TaskStatus $status) : void
    {
        if ($status->id === Task::STATUS_TODO || $status->id === Task::STATUS_COMPLETED) {
            $_c241f11ec2591cc626823468234ffaf4 = $status->id === Task::STATUS_TODO ? $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_5f4d1ad89c9415004" . "71a8370398dad9e"] : $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_9ed84d2923d81db75e6348d1b290" . "c051"];
            $project = $this->project_provider->GetProject($status->project_id);
            $project->SetProperty($_c241f11ec2591cc626823468234ffaf4, $status->name);
            $this->project_provider->SaveProject($project);
        } elseif ($status->id >= 0) {
            $_5693d84b45564f912e36404cbe8957e8 = $status->id === 0 ? TaskStatusEvents::PRE_CREATE : TaskStatusEvents::PRE_EDIT;
            $_e62ca7bbb93b52cafc82da1c2aefe9ec = new GenericEvent($status);
            $this->dispatcher->dispatch($_5693d84b45564f912e36404cbe8957e8, $_e62ca7bbb93b52cafc82da1c2aefe9ec);
            $this->checkEvent($_e62ca7bbb93b52cafc82da1c2aefe9ec, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_cb79f297f1fbf916b9e421a8de" . "7e9b0f"]);
            $this->repository->store($status);
            $_5693d84b45564f912e36404cbe8957e8 = $status->id === 0 ? TaskStatusEvents::CREATED : TaskStatusEvents::EDITED;
            $_e62ca7bbb93b52cafc82da1c2aefe9ec = new GenericEvent($status);
            $this->dispatcher->dispatch($_5693d84b45564f912e36404cbe8957e8, $_e62ca7bbb93b52cafc82da1c2aefe9ec);
        }
    }
    public function DeleteStatus(TaskStatus $status) : void
    {
        $_e62ca7bbb93b52cafc82da1c2aefe9ec = new GenericEvent($status);
        $this->dispatcher->dispatch(TaskStatusEvents::PRE_DELETE, $_e62ca7bbb93b52cafc82da1c2aefe9ec);
        $this->checkEvent($_e62ca7bbb93b52cafc82da1c2aefe9ec, $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_507a6b14e352bf" . "9974b4646608163" . "e0d"]);
        $this->repository->delete($status);
        $this->StatusDeletedHistory($status);
        $_e62ca7bbb93b52cafc82da1c2aefe9ec = new GenericEvent($status);
        $this->dispatcher->dispatch(TaskStatusEvents::DELETED, $_e62ca7bbb93b52cafc82da1c2aefe9ec);
    }
    
    
    
    
    
    
    protected function checkEvent(GenericEvent $_e62ca7bbb93b52cafc82da1c2aefe9ec, string $_a2394ddd74e4be57f1ab2ea1e97640c0)
    {
        if ($_e62ca7bbb93b52cafc82da1c2aefe9ec->isPropagationStopped()) {
            $message = $_a2394ddd74e4be57f1ab2ea1e97640c0;
            if ($_e62ca7bbb93b52cafc82da1c2aefe9ec->hasArgument($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["messa" . "ge"])) {
                $message = $_e62ca7bbb93b52cafc82da1c2aefe9ec->getArgument($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["messag" . "e"]);
            }
            throw new StatusStorageException($message);
        }
    }
    public function StatusAddedHistory(TaskStatus $status)
    {
        $_6be7ef0f685c2a96fcae1fc2ccc30198 = [$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_dadf790baf241afac942824c1e6" . "e37c4"] => $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_1eb40133422266" . "84733e3c83e4fcf" . "f5a"], $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_feb9037589181bc30fa0f1" . "cf78b9f056"] => $this->text_utils->HtmlSafe($status->name)];
        $_a82e7c9cba13670954fbe01d604c242a = new HistoryItem();
        $_a82e7c9cba13670954fbe01d604c242a->SetArea(($this->lmsg)($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_f3378ee2ffbe610a7d709e577" . "c7b3409"]));
        $_a82e7c9cba13670954fbe01d604c242a->SetChanges($_6be7ef0f685c2a96fcae1fc2ccc30198);
        $this->history_service->AddHistoryForCurrentUser(Permissions::PROJECT_AGGREGATION, $status->project_id, $_a82e7c9cba13670954fbe01d604c242a);
    }
    public function StatusUpdatedHistory(TaskStatus $_9bacb470d4f91e74f3caafec23aeca8e, TaskStatus $_ed9e26151db293a5d9b6cf0bc61ee2f4)
    {
        $_6be7ef0f685c2a96fcae1fc2ccc30198 = [$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_dadf790baf241afac942824c1e6e3" . "7c4"] => $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_546c50a2525e1b6eeefb4a2ffcef68" . "33"], $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_feb9037589181bc30fa0f1cf7" . "8b9f056"] => $this->text_utils->HtmlSafe($_ed9e26151db293a5d9b6cf0bc61ee2f4->name), $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_6be7ef0f6" . "85c2a96fca" . "e1fc2ccc30" . "198"] => []];
        if ($_9bacb470d4f91e74f3caafec23aeca8e->name !== $_ed9e26151db293a5d9b6cf0bc61ee2f4->name) {
            $_6be7ef0f685c2a96fcae1fc2ccc30198[$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_6be7ef0f685c2a96fcae1fc" . "2ccc30198"]][] = [$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_dadf790baf241af" . "ac942824c1e6e37c" . "4"] => $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_feb9037589181bc30fa0f" . "1cf78b9f056"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_f0d3cd92e3eb44" . "17d5898658673ed" . "aa4"] => $this->text_utils->HtmlSafe($_9bacb470d4f91e74f3caafec23aeca8e->name), $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_25983d06eff5f52f829961d" . "6bf1a7a70"] => $this->text_utils->HtmlSafe($_ed9e26151db293a5d9b6cf0bc61ee2f4->name)];
        }
        $_a82e7c9cba13670954fbe01d604c242a = new HistoryItem();
        $_a82e7c9cba13670954fbe01d604c242a->SetArea(($this->lmsg)($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_f3378ee2ffbe610a7d709e577c7b340" . "9"]));
        $_a82e7c9cba13670954fbe01d604c242a->SetChanges($_6be7ef0f685c2a96fcae1fc2ccc30198);
        $this->history_service->AddHistoryForCurrentUser(Permissions::PROJECT_AGGREGATION, $_ed9e26151db293a5d9b6cf0bc61ee2f4->project_id, $_a82e7c9cba13670954fbe01d604c242a);
    }
    public function StatusDeletedHistory(TaskStatus $status)
    {
        $_6be7ef0f685c2a96fcae1fc2ccc30198 = [$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_dadf790baf2" . "41afac942824" . "c1e6e37c4"] => $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_52c88622c68f9" . "de6e59b3146dc7" . "09dc5"], $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_feb90375" . "89181bc30" . "fa0f1cf78" . "b9f056"] => $this->text_utils->HtmlSafe($status->name)];
        $_a82e7c9cba13670954fbe01d604c242a = new HistoryItem();
        $_a82e7c9cba13670954fbe01d604c242a->SetArea(($this->lmsg)($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_f3378ee2ffbe61" . "0a7d709e577c7b3" . "409"]));
        $_a82e7c9cba13670954fbe01d604c242a->SetChanges($_6be7ef0f685c2a96fcae1fc2ccc30198);
        $this->history_service->AddHistoryForCurrentUser(Permissions::PROJECT_AGGREGATION, $status->project_id, $_a82e7c9cba13670954fbe01d604c242a);
    }
}