<?php
namespace Claromentis\Pages\UseCase;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"] = (@$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"] ?: array()) + array("_69a049bb19c215a3e521ce4beb5" . "b3cde" => base64_decode("JyBhdCB" . "VUkwgJw" . "=="), "_3d6a0bf37eb57647" . "cdf8d3afb62d3ba2" => base64_decode("cGFnZXMuZGVsZXRlX3NpdGUubm9fcmlna" . "HRz"), "_3f05c7e033d5fa5883b" . "27e9248e3ab53" => base64_decode("cGFn" . "ZXM="), "_ce0be79d1401ad6480c5c836eab1a7" . "46" => base64_decode("JyBtb3ZlZ" . "CB0byByZW" . "N5Y2xlIGJ" . "pbg=="), "_a2d272b74ef8bd3f" . "4e651ff44afb31c6" => base64_decode("U2l0" . "ZSAn"), "_0c5123aa744f69bbc0e8b3ea2f6e8" . "47d" => base64_decode("bG1z" . "Zw=="), "_d4c3ce992b04" . "817c9359b52e3" . "e0f28bc" => base64_decode("JyBkZWxldGVkIGZyb20gcmVjeWNsZSBiaW4" . "="), "_932e6eba1966ec8d2ebadb2f04cbd7b" . "0" => base64_decode("ZGVsZXRl" . "X3NpdGU="));
use Claromentis\Core\Acl\Acl;
use Claromentis\Core\Audit\Audit;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\Pages\Exception\AccessDeniedException;
use Claromentis\Pages\Model\Site;
use Claromentis\Pages\PagesAcl;
use Claromentis\Pages\Perm;
use Claromentis\Pages\Repository\MenuItemRepository;
use Claromentis\Pages\Repository\SiteRepository;
use Claromentis\Pages\Repository\UrlRepository;
use Claromentis\Pages\TrashCan\TrashObjectSite;




class DeleteSite
{
    protected PagesAcl $acl;
    protected SiteRepository $site_repository;
    protected MenuItemRepository $menu_item_repository;
    protected UrlRepository $url_repository;
    protected DeleteMenuItem $delete_menu_item;
    protected Audit $audit;
    public function __construct(PagesAcl $acl, SiteRepository $_3d34b0ca12d1109977100f7f660f3a9b, MenuItemRepository $_10aca790e0352d5c4b5c3bbaa9c9a43e, UrlRepository $_0ffc8e5433da0b1c27f79e871fb130bc, DeleteMenuItem $_e4294240d703581140aadc02243c1153, Audit $audit)
    {
        $this->acl = $acl;
        $this->site_repository = $_3d34b0ca12d1109977100f7f660f3a9b;
        $this->menu_item_repository = $_10aca790e0352d5c4b5c3bbaa9c9a43e;
        $this->url_repository = $_0ffc8e5433da0b1c27f79e871fb130bc;
        $this->delete_menu_item = $_e4294240d703581140aadc02243c1153;
        $this->audit = $audit;
    }
    
    
    
    
    
    
    
    public function EnsureCanDelete(SecurityContext $context, $site_id)
    {
        if (!$this->acl->CanDeleteSite($context, $site_id)) {
            throw new AccessDeniedException($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_0c5123aa744f69bb" . "c0e8b3ea2f6e847d"]($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_3d6a0bf3" . "7eb57647c" . "df8d3afb6" . "2d3ba2"]));
        }
    }
    
    
    
    
    
    
    
    public function DeleteById(SecurityContext $context, $site_id)
    {
        
        
        $_ad6d1395fad94fb16ed12d8007727518 = $this->site_repository->Get($site_id);
        $this->Delete($context, $_ad6d1395fad94fb16ed12d8007727518);
    }
    
    
    
    
    
    
    
    
    public function Delete(SecurityContext $context, Site $_ad6d1395fad94fb16ed12d8007727518)
    {
        $this->EnsureCanDelete($context, $_ad6d1395fad94fb16ed12d8007727518->id);
        $url = $this->url_repository->GetById($_ad6d1395fad94fb16ed12d8007727518->url_id);
        $_32bfb1036b8a8d86c4568f01ebd95a94 = $url->GetUrl();
        $_795905ef2d5532f75842cf1ecb7b2676 = new TrashObjectSite($_ad6d1395fad94fb16ed12d8007727518);
        $_795905ef2d5532f75842cf1ecb7b2676->Save();
        $this->site_repository->FlagAsDeleted($_ad6d1395fad94fb16ed12d8007727518->id);
        $_d43c6db6d25c2749f65bc7bc28bd8df3 = $this->menu_item_repository->GetByUrlId($_ad6d1395fad94fb16ed12d8007727518->url_id);
        if ($_d43c6db6d25c2749f65bc7bc28bd8df3 !== null) {
            $this->delete_menu_item->DeleteIndex($_d43c6db6d25c2749f65bc7bc28bd8df3);
        }
        $_feb9037589181bc30fa0f1cf78b9f056 = $_ad6d1395fad94fb16ed12d8007727518->title;
        
        
        $this->audit->success($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_3f05c7e033d5fa5883b2" . "7e9248e3ab53"], $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_932e6eba1966ec8d2ebadb2f" . "04cbd7b0"], $_ad6d1395fad94fb16ed12d8007727518->id, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_a2d272b74ef8bd" . "3f4e651ff44afb3" . "1c6"] . $_feb9037589181bc30fa0f1cf78b9f056 . $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_69a049bb" . "19c215a3e" . "521ce4beb" . "5b3cde"] . $_32bfb1036b8a8d86c4568f01ebd95a94 . $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_ce0be79d1401ad6480c5" . "c836eab1a746"]);
    }
    
    
    
    
    
    
    
    
    public function FullDelete(Site $_ad6d1395fad94fb16ed12d8007727518)
    {
        $url = $this->url_repository->GetById($_ad6d1395fad94fb16ed12d8007727518->url_id);
        $_32bfb1036b8a8d86c4568f01ebd95a94 = $url->GetUrl();
        $_d43c6db6d25c2749f65bc7bc28bd8df3 = $this->menu_item_repository->GetByUrlId($_ad6d1395fad94fb16ed12d8007727518->url_id);
        if ($_d43c6db6d25c2749f65bc7bc28bd8df3 !== null) {
            $this->delete_menu_item->FullDelete($_d43c6db6d25c2749f65bc7bc28bd8df3);
        }
        $_feb9037589181bc30fa0f1cf78b9f056 = $_ad6d1395fad94fb16ed12d8007727518->title;
        $this->acl->SetSiteAcl($_ad6d1395fad94fb16ed12d8007727518->id, new Acl(Perm::CLASS_SITE));
        $this->site_repository->Delete($_ad6d1395fad94fb16ed12d8007727518);
        
        
        $this->audit->success($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_3f05c7e033d5fa5883b" . "27e9248e3ab53"], $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_932e6eba196" . "6ec8d2ebadb2" . "f04cbd7b0"], $_ad6d1395fad94fb16ed12d8007727518->id, $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_a2d272b74ef8bd3f4" . "e651ff44afb31c6"] . $_feb9037589181bc30fa0f1cf78b9f056 . $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_69a049bb19c215a3e521ce4b" . "eb5b3cde"] . $_32bfb1036b8a8d86c4568f01ebd95a94 . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_d4c3ce992b04817c9359b52" . "e3e0f28bc"]);
    }
    public function FullDeleteById(int $site_id)
    {
        $_ad6d1395fad94fb16ed12d8007727518 = $this->site_repository->GetById($site_id);
        
        
        if ($_ad6d1395fad94fb16ed12d8007727518 !== null) {
            $this->FullDelete($_ad6d1395fad94fb16ed12d8007727518);
        }
    }
}