<?php
namespace Claromentis\Pages\UseCase;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"] = (@$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"] ?: array()) + array("_932e6eba1966ec8d2" . "ebadb2f04cbd7b0" => base64_decode("ZGVsZXRlX3" . "NpdGU="), "_a2d272b74ef8bd3f4e651ff44afb" . "31c6" => base64_decode("U2l0ZSA" . "n"), "_69a049bb19c215a3e521ce4beb5b3" . "cde" => base64_decode("JyBhdCBVUkwgJw=" . "="), "_d4c3ce992b04817c93" . "59b52e3e0f28bc" => base64_decode("JyBkZWxldGVkIGZyb20gcmVjeWNsZSBia" . "W4="), "_3d6a0bf37eb57647cdf8d3" . "afb62d3ba2" => base64_decode("cGFnZXMuZGVsZXRlX3NpdGU" . "ubm9fcmlnaHRz"), "_0c5123aa744f69bbc0e8b3ea2f6e84" . "7d" => base64_decode("bG1" . "zZw" . "=="), "_3f05c7e033d5fa5883b27e9248e3a" . "b53" => base64_decode("cGFnZ" . "XM="), "_ce0be79d1401ad6480c5" . "c836eab1a746" => base64_decode("JyBtb3ZlZCB0byByZWN5Y2xlI" . "GJpbg=="));
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["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_0c5123aa7" . "44f69bbc0e" . "8b3ea2f6e8" . "47d"]($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_3d6a0bf37eb57647" . "cdf8d3afb62d3ba2"]));
        }
    }
    
    
    
    
    
    
    
    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["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_3f05c7e033d5fa5883b27e9248e" . "3ab53"], $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_932e6eba1966" . "ec8d2ebadb2f0" . "4cbd7b0"], $_ad6d1395fad94fb16ed12d8007727518->id, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_a2d272b74ef8bd3f4e651ff44afb31" . "c6"] . $_feb9037589181bc30fa0f1cf78b9f056 . $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_69a049bb19c215" . "a3e521ce4beb5b3" . "cde"] . $_32bfb1036b8a8d86c4568f01ebd95a94 . $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_ce0be79d1401ad6480c5c836" . "eab1a746"]);
    }
    
    
    
    
    
    
    
    
    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["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_3f05c7e033" . "d5fa5883b27" . "e9248e3ab53"], $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_932e6eba1966ec8d2ebadb2f04" . "cbd7b0"], $_ad6d1395fad94fb16ed12d8007727518->id, $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_a2d272b74ef8bd3f4e65" . "1ff44afb31c6"] . $_feb9037589181bc30fa0f1cf78b9f056 . $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_69a049bb19c215a3e52" . "1ce4beb5b3cde"] . $_32bfb1036b8a8d86c4568f01ebd95a94 . $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_d4c3ce992b04817c9359b52e3" . "e0f28bc"]);
    }
    public function FullDeleteById(int $site_id)
    {
        $_ad6d1395fad94fb16ed12d8007727518 = $this->site_repository->GetById($site_id);
        
        
        if ($_ad6d1395fad94fb16ed12d8007727518 !== null) {
            $this->FullDelete($_ad6d1395fad94fb16ed12d8007727518);
        }
    }
}