<?php
namespace Claromentis\Pages\UseCase;

$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"] ?: array()) + array("_c9694006d8756c82c46117" . "f459bbd125" => base64_decode("JyBtb3ZlZCB0byByZWN5Y2xlIGJpbiBmcm9tIHNpdGU" . "gIw=="), "_80b5614b10ea7483addd4" . "55ff7e14fb8" => base64_decode("ZGVsZXRlX3BhZ2U" . "="), "_3f05c7e033d5fa5883b27e92" . "48e3ab53" => base64_decode("cGFnZX" . "M="), "_8fbd1db" . "aad55bed" . "6e65cd4e" . "c8b976b9" . "d" => base64_decode("JyBkZWxldGVkIGZyb20gcmVjeWNsZSBiaW4gdGhhdCB3YXMg" . "cGFydCBvZiBzaXRlICM="), "_c15063b64cfbba4f0" . "ac20a9af3702823" => base64_decode("ZGVsZ" . "XRlX2" . "xpbms" . "="), "_c391253b5c2c500e6799a20a6ce0" . "a184" => base64_decode("cGFnZXMubWVudS5lcnJv" . "ci5ub19kZWxldGVfcmln" . "aHRzX2luX3NpdGU="), "_cc9ea38794e79db7091bc3dff264403" . "1" => base64_decode("JyB0by" . "BVUkwg" . "Jw=="), "_69a049bb19c215a3" . "e521ce4beb5b3cde" => base64_decode("JyBhd" . "CBVUk" . "wgJw=" . "="), "_747fbe6ec43131" . "290c5d78fd1e990" . "39c" => base64_decode("UGFnZS" . "An"), "_0c5123aa744f69bbc0e8b3ea2f6e84" . "7d" => base64_decode("bG" . "1z" . "Zw" . "=="), "_0c5b488" . "7f2265da" . "e5490ad8" . "b407d875" . "2" => base64_decode("TGlua" . "yAn"));
use Claromentis\Core\Audit\Audit;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\Pages\Exception\AccessDeniedException;
use Claromentis\Pages\Facade\DeletePageUrl;
use Claromentis\Pages\Model\MenuItem;
use Claromentis\Pages\PagesAcl;
use Claromentis\Pages\Repository\MenuItemRepository;
use Claromentis\Pages\Repository\UrlRepository;
use Claromentis\Pages\Search\Indexing\PageIndexing;
use Claromentis\Pages\TrashCan\TrashObjectMenuItem;
use Claromentis\Search\Indexing\IndexingQueue;




class DeleteMenuItem
{
    protected $acl;
    protected $menu_item_repository;
    protected UrlRepository $url_repository;
    protected $delete_url;
    protected Audit $audit;
    public function __construct(PagesAcl $acl, MenuItemRepository $_10aca790e0352d5c4b5c3bbaa9c9a43e, UrlRepository $_0ffc8e5433da0b1c27f79e871fb130bc, DeletePageUrl $_66ecb2737a3d9ebdc7e982753f86d5f6, Audit $audit)
    {
        $this->acl = $acl;
        $this->menu_item_repository = $_10aca790e0352d5c4b5c3bbaa9c9a43e;
        $this->url_repository = $_0ffc8e5433da0b1c27f79e871fb130bc;
        $this->delete_url = $_66ecb2737a3d9ebdc7e982753f86d5f6;
        $this->audit = $audit;
    }
    
    
    
    
    
    
    
    public function DeleteById(SecurityContext $context, $_a1053c2fc8090400c07497f8420a3587)
    {
        $_d43c6db6d25c2749f65bc7bc28bd8df3 = $this->menu_item_repository->GetById($_a1053c2fc8090400c07497f8420a3587);
        if (!$_d43c6db6d25c2749f65bc7bc28bd8df3) {
            return;
        }
        $this->Delete($context, $_d43c6db6d25c2749f65bc7bc28bd8df3);
    }
    
    
    
    
    
    
    
    
    
    public function Delete(SecurityContext $context, MenuItem $_d43c6db6d25c2749f65bc7bc28bd8df3)
    {
        if (!$this->acl->CanDeleteMenuItem($context, $_d43c6db6d25c2749f65bc7bc28bd8df3)) {
            throw new AccessDeniedException($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_0c5123aa744f69bbc0e" . "8b3ea2f6e847d"]($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_c391253b5c2c500e6799a20a6c" . "e0a184"]));
        }
        $_795905ef2d5532f75842cf1ecb7b2676 = new TrashObjectMenuItem($_d43c6db6d25c2749f65bc7bc28bd8df3);
        $_795905ef2d5532f75842cf1ecb7b2676->Save();
        $this->menu_item_repository->FlagAsDeleted($_d43c6db6d25c2749f65bc7bc28bd8df3->id);
        if ((int) $_d43c6db6d25c2749f65bc7bc28bd8df3->type === MenuItem::LINK_TYPE_PAGE) {
            $url = $this->url_repository->GetById($_d43c6db6d25c2749f65bc7bc28bd8df3->url_id);
            $_32bfb1036b8a8d86c4568f01ebd95a94 = $url->GetUrl();
            $this->DeleteIndex($_d43c6db6d25c2749f65bc7bc28bd8df3);
            $this->audit->Success($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_3f05c7e033d5fa5883b27e92" . "48e3ab53"], $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_80b5614b10ea7483a" . "ddd455ff7e14fb8"], $_d43c6db6d25c2749f65bc7bc28bd8df3->url_id, $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_747fbe6ec43131" . "290c5d78fd1e990" . "39c"] . $_795905ef2d5532f75842cf1ecb7b2676->title . $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_69a049bb19c215a3e521ce4beb5b" . "3cde"] . $_32bfb1036b8a8d86c4568f01ebd95a94 . $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_c9694006d8756c82c46117f4" . "59bbd125"] . $_d43c6db6d25c2749f65bc7bc28bd8df3->site_id);
        } else {
            $this->audit->Success($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_3f05c7e033d5f" . "a5883b27e9248e" . "3ab53"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_c15063b64cfbba4f0ac20a9" . "af3702823"], $_d43c6db6d25c2749f65bc7bc28bd8df3->id, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_0c5b4887f2265dae549" . "0ad8b407d8752"] . $_d43c6db6d25c2749f65bc7bc28bd8df3->title . $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_cc9ea38794e79db7091bc3dff26" . "44031"] . $_d43c6db6d25c2749f65bc7bc28bd8df3->link_url . $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_c9694006d8756c82c46117f4" . "59bbd125"] . $_d43c6db6d25c2749f65bc7bc28bd8df3->site_id);
        }
    }
    
    
    
    
    
    
    
    
    
    
    public function DeleteIndex(MenuItem $_d43c6db6d25c2749f65bc7bc28bd8df3)
    {
        $_98121e94e148d73a15700996ba4d7a53 = $this->menu_item_repository->GetChildrenByParentId($_d43c6db6d25c2749f65bc7bc28bd8df3->id);
        foreach ($_98121e94e148d73a15700996ba4d7a53 as $_1bd6e5a007d5639e67837f0567493081) {
            $this->DeleteIndex($_1bd6e5a007d5639e67837f0567493081);
        }
        if ((int) $_d43c6db6d25c2749f65bc7bc28bd8df3->type === MenuItem::LINK_TYPE_PAGE) {
            IndexingQueue::DeleteIndex(PageIndexing::TYPE_NAME, $_d43c6db6d25c2749f65bc7bc28bd8df3->url_id);
        }
    }
    
    
    
    
    
    
    public function FullDelete(MenuItem $_d43c6db6d25c2749f65bc7bc28bd8df3)
    {
        
        
        $_98121e94e148d73a15700996ba4d7a53 = $this->menu_item_repository->GetChildrenByParentId($_d43c6db6d25c2749f65bc7bc28bd8df3->id);
        foreach ($_98121e94e148d73a15700996ba4d7a53 as $_1bd6e5a007d5639e67837f0567493081) {
            $this->FullDelete($_1bd6e5a007d5639e67837f0567493081);
        }
        if ((int) $_d43c6db6d25c2749f65bc7bc28bd8df3->type === MenuItem::LINK_TYPE_PAGE) {
            $url = $this->url_repository->GetById($_d43c6db6d25c2749f65bc7bc28bd8df3->url_id);
            $_32bfb1036b8a8d86c4568f01ebd95a94 = $url->GetUrl();
            $this->delete_url->DeleteOneById($_d43c6db6d25c2749f65bc7bc28bd8df3->url_id);
            $this->audit->Success($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_3f05c7e033d5fa5883b27e9" . "248e3ab53"], $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_80b5614b10ea7483addd4" . "55ff7e14fb8"], $_d43c6db6d25c2749f65bc7bc28bd8df3->url_id, $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_747fbe6ec431" . "31290c5d78fd1" . "e99039c"] . $_d43c6db6d25c2749f65bc7bc28bd8df3->title . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_69a049bb19c21" . "5a3e521ce4beb5" . "b3cde"] . $_32bfb1036b8a8d86c4568f01ebd95a94 . $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_8fbd1dbaad55bed6e65cd4ec" . "8b976b9d"] . $_d43c6db6d25c2749f65bc7bc28bd8df3->site_id);
        } else {
            $this->audit->Success($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_3f05c7e033d5fa5883b27e9248e3ab5" . "3"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_c15063b64cfbba4f0ac20a" . "9af3702823"], $_d43c6db6d25c2749f65bc7bc28bd8df3->id, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_0c5b4887f2265dae5" . "490ad8b407d8752"] . $_d43c6db6d25c2749f65bc7bc28bd8df3->title . $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_cc9ea387" . "94e79db70" . "91bc3dff2" . "644031"] . $_d43c6db6d25c2749f65bc7bc28bd8df3->link_url . $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_8fbd1dbaad55bed6e65cd4ec8b" . "976b9d"] . $_d43c6db6d25c2749f65bc7bc28bd8df3->site_id);
        }
        
        
        $this->menu_item_repository->Delete($_d43c6db6d25c2749f65bc7bc28bd8df3);
    }
    public function FullDeleteById(int $menuitem_id)
    {
        $_56215161cab963ee6e3f7a77dbd5feee = $this->menu_item_repository->GetById($menuitem_id);
        
        
        if ($_56215161cab963ee6e3f7a77dbd5feee !== null) {
            $this->FullDelete($_56215161cab963ee6e3f7a77dbd5feee);
        }
    }
}