<?php
namespace Claromentis\Pages\UseCase;

$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"] ?: array()) + array("_c391253b5c2c500e6799a" . "20a6ce0a184" => base64_decode("cGFnZXMubWVudS5lcnJvci5ub19kZWxldGVfcmlnaHRzX2luX3NpdGU" . "="), "_747fbe6ec43131290c5d78fd1e99039" . "c" => base64_decode("UGF" . "nZS" . "An"), "_8fbd1dbaad55bed6" . "e65cd4ec8b976b9d" => base64_decode("JyBkZWxldGVkIGZyb20gcmVjeWN" . "sZSBiaW4gdGhhdCB3YXMgcGFydC" . "BvZiBzaXRlICM="), "_0c5b4887f2265dae5490a" . "d8b407d8752" => base64_decode("TGl" . "uay" . "An"), "_0c5123aa74" . "4f69bbc0e8b" . "3ea2f6e847d" => base64_decode("bG1" . "zZw" . "=="), "_cc9ea38794e79db7091bc3dff26440" . "31" => base64_decode("JyB0by" . "BVUkwg" . "Jw=="), "_c9694006d8756c82c4611" . "7f459bbd125" => base64_decode("JyBtb3ZlZCB0byByZWN5Y2xlIGJpbiBmcm9" . "tIHNpdGUgIw=="), "_c15063b64cfbba4f0ac2" . "0a9af3702823" => base64_decode("ZGVsZXRlX2xpb" . "ms="), "_69a049bb1" . "9c215a3e52" . "1ce4beb5b3" . "cde" => base64_decode("JyBhd" . "CBVUk" . "wgJw=" . "="), "_80b5614b10ea74" . "83addd455ff7e14" . "fb8" => base64_decode("ZGVsZXRl" . "X3BhZ2U="), "_3f05c7e0" . "33d5fa588" . "3b27e9248" . "e3ab53" => base64_decode("cGF" . "nZX" . "M="));
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["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_0c5123aa744" . "f69bbc0e8b3e" . "a2f6e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_c391253b5c2c500e6799a20a6" . "ce0a184"]));
        }
        $_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["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_3f05c7e033d5fa5883b2" . "7e9248e3ab53"], $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_80b5614b10ea7483addd45" . "5ff7e14fb8"], $_d43c6db6d25c2749f65bc7bc28bd8df3->url_id, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_747fbe6ec43131290c5d" . "78fd1e99039c"] . $_795905ef2d5532f75842cf1ecb7b2676->title . $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_69a049bb19c215a3e521ce4beb5" . "b3cde"] . $_32bfb1036b8a8d86c4568f01ebd95a94 . $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_c9694006d8756c82c46117f459b" . "bd125"] . $_d43c6db6d25c2749f65bc7bc28bd8df3->site_id);
        } else {
            $this->audit->Success($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_3f05c7e03" . "3d5fa5883b" . "27e9248e3a" . "b53"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_c15063b64cfbba4f0ac20a9a" . "f3702823"], $_d43c6db6d25c2749f65bc7bc28bd8df3->id, $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_0c5b4887f2265d" . "ae5490ad8b407d8" . "752"] . $_d43c6db6d25c2749f65bc7bc28bd8df3->title . $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_cc9ea387" . "94e79db70" . "91bc3dff2" . "644031"] . $_d43c6db6d25c2749f65bc7bc28bd8df3->link_url . $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_c9694006d8756" . "c82c46117f459b" . "bd125"] . $_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["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_3f05c7e033d5fa5883b27e92" . "48e3ab53"], $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_80b5614b10ea7483addd455ff7e1" . "4fb8"], $_d43c6db6d25c2749f65bc7bc28bd8df3->url_id, $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_747fbe6ec4313" . "1290c5d78fd1e9" . "9039c"] . $_d43c6db6d25c2749f65bc7bc28bd8df3->title . $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_69a049bb19c215a" . "3e521ce4beb5b3cd" . "e"] . $_32bfb1036b8a8d86c4568f01ebd95a94 . $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_8fbd1dbaad55bed6e65c" . "d4ec8b976b9d"] . $_d43c6db6d25c2749f65bc7bc28bd8df3->site_id);
        } else {
            $this->audit->Success($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_3f05c7e0" . "33d5fa588" . "3b27e9248" . "e3ab53"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_c15063b64c" . "fbba4f0ac20" . "a9af3702823"], $_d43c6db6d25c2749f65bc7bc28bd8df3->id, $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_0c5b4887f2265dae5490ad8b40" . "7d8752"] . $_d43c6db6d25c2749f65bc7bc28bd8df3->title . $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_cc9ea38794e79db7091" . "bc3dff2644031"] . $_d43c6db6d25c2749f65bc7bc28bd8df3->link_url . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_8fbd1dbaad55" . "bed6e65cd4ec8" . "b976b9d"] . $_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);
        }
    }
}