<?php
namespace Claromentis\Core\Plugin;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"] = (@$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"] ?: array()) + array("_c51bc96058fbdbf4" . "c2ef19b306d1a124" => base64_decode("Y2xhc3NfZXhpc3R" . "z"), "_35ed77ccccaf3a056dc" . "f16acae33bbe0" => base64_decode("Y2" . "xh" . "c3" . "M="), "_ea8229a121285ee649" . "a72fd880bac39b" => base64_decode("YXJyYXl" . "fZmlsdG" . "Vy"), "_60d55624216a008453c890fdf17e" . "4fbe" => base64_decode("JyBwbHVnaW4gc3RhdHVzIHV" . "wZGF0ZWQgZnJvbSAn"), "_c87518f15b2c098ea498f34" . "04e7d3ff9" => base64_decode("cHJldml" . "vdXNTdG" . "F0dXM="), "_cf4d8ef1a5059866b44a176b7f88900" . "3" => base64_decode("Jy" . "B0" . "by" . "An"), "_e608e5b5c4c34a67ba97e" . "f84c1e16199" => base64_decode("Jw" . "=="), "c" . "o" . "d" . "e" => base64_decode("Y2" . "9k" . "ZQ" . "=="), "_c35473364fa7a050299058f" . "332ec29c1" => base64_decode("ZXhjZXB" . "0aW9u"), "_3ef28170d0a5fc24f96" . "12e5b65d09b4c" => base64_decode("RXJyb3I" . "gdXBkYX" . "RpbmcgJ" . "w=="), "_6c40c95e1e19" . "17386016d93d6" . "261f85d" => base64_decode("aW50ZW5kZWRTdGF0dXM" . "="), "_d0845bff5cd0ddb5ed1d7bd" . "9db996f51" => base64_decode("c291cmN" . "l"), "statu" . "s" => base64_decode("c3Rh" . "dHVz"), "_0eaf2641d" . "20998e3cd9" . "d523a60dd1" . "f3c" => base64_decode("JyBwbHVnaW4" . "gc3RhdHVzIH" . "RvICc="));
use Claromentis\Core\Event\EventDispatcherInterface;
use Claromentis\Core\Event\EventSources;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\NullLogger;
use Throwable;















class Api implements LoggerAwareInterface
{
    use LoggerAwareTrait;
    protected PluginsRepository $repository;
    protected EventDispatcherInterface $dispatcher;
    public function __construct(PluginsRepository $_8652ba33e6ffeba02459fa9cbb320851, EventDispatcherInterface $_b497ce6f2af10f67516aed0ecf34d8cf)
    {
        $this->repository = $_8652ba33e6ffeba02459fa9cbb320851;
        $this->dispatcher = $_b497ce6f2af10f67516aed0ecf34d8cf;
        $this->logger = new NullLogger();
    }
    
    
    
    
    
    
    
    public function exists(string $code) : bool
    {
        $_6aead4bff5639b251aebcf8a630e43a7 = $this->repository->GetInfo($code);
        return isset($_6aead4bff5639b251aebcf8a630e43a7[$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_35ed77ccccaf" . "3a056dcf16aca" . "e33bbe0"]]) && $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_c51bc96058fb" . "dbf4c2ef19b30" . "6d1a124"]($_6aead4bff5639b251aebcf8a630e43a7[$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_35ed77ccccaf3a0" . "56dcf16acae33bbe" . "0"]]);
    }
    
    
    
    
    
    
    
    public function remove(string $code) : void
    {
        $this->repository->Remove($code);
    }
    
    
    
    
    
    
    
    
    
    
    public function getStatus(string $code) : int
    {
        return $this->repository->GetStatus($code);
    }
    
    
    
    
    
    
    
    public function isEnabled(string $code) : bool
    {
        return $this->getStatus($code) === Statuses::ENABLED;
    }
    
    
    
    
    
    
    
    
    
    
    public function setEnabled(string $code, bool $_99cee2d2272a8550f4b21e3cb57fff7d, string $_d0845bff5cd0ddb5ed1d7bd9db996f51 = EventSources::WEB) : PluginStatusEvent
    {
        return $this->setPluginStatus($code, $_99cee2d2272a8550f4b21e3cb57fff7d, $_d0845bff5cd0ddb5ed1d7bd9db996f51);
    }
    
    
    
    
    
    
    
    
    
    public function enable(string $code, string $_d0845bff5cd0ddb5ed1d7bd9db996f51 = EventSources::WEB) : PluginStatusEvent
    {
        return $this->setEnabled($code, true, $_d0845bff5cd0ddb5ed1d7bd9db996f51);
    }
    
    
    
    
    
    
    
    
    
    public function disable(string $code, string $_d0845bff5cd0ddb5ed1d7bd9db996f51 = EventSources::WEB) : PluginStatusEvent
    {
        return $this->setEnabled($code, false, $_d0845bff5cd0ddb5ed1d7bd9db996f51);
    }
    
    
    
    
    
    
    
    
    
    
    protected function setPluginStatus(string $code, bool $_99cee2d2272a8550f4b21e3cb57fff7d, string $_d0845bff5cd0ddb5ed1d7bd9db996f51) : PluginStatusEvent
    {
        $_2cf093f28f4c7e718a5e8af628894c7b = PluginEvents::STATUS;
        $_6c40c95e1e1917386016d93d6261f85d = $_99cee2d2272a8550f4b21e3cb57fff7d ? Statuses::ENABLED : Statuses::DISABLED;
        try {
            $_c87518f15b2c098ea498f3404e7d3ff9 = $this->repository->GetStatus($code);
            $this->repository->SetEnabled($code, $_99cee2d2272a8550f4b21e3cb57fff7d);
            $status = $this->repository->GetStatus($code);
            $event = new PluginStatusEvent($code, $_6c40c95e1e1917386016d93d6261f85d, $_c87518f15b2c098ea498f3404e7d3ff9, $status, $_d0845bff5cd0ddb5ed1d7bd9db996f51);
        } catch (Throwable $_c35473364fa7a050299058f332ec29c1) {
            
            
            $event = new PluginStatusEvent($code, $_6c40c95e1e1917386016d93d6261f85d, Statuses::DISABLED, Statuses::DISABLED, $_d0845bff5cd0ddb5ed1d7bd9db996f51, $_c35473364fa7a050299058f332ec29c1);
        } finally {
            $this->dispatcher->dispatch($event, $_2cf093f28f4c7e718a5e8af628894c7b);
            $context = $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_ea8229a12128" . "5ee649a72fd88" . "0bac39b"]([$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["co" . "de"] => $event->getCode(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["statu" . "s"] => $event->getStatusName(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_c87518f15b2c098ea498" . "f3404e7d3ff9"] => $event->getPreviousStatusName(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_6c40c95e1e1917386016d93d62" . "61f85d"] => $event->getIntendedStatusName(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_d0845bff5cd0ddb5ed1d" . "7bd9db996f51"] => $event->getSource(), $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_c35473364fa7a0502990" . "58f332ec29c1"] => $event->getThrowable()]);
            if ($event->success()) {
                $this->logger->notice($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_e608e5b5c4c34a67ba97ef84c1" . "e16199"] . $code . $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_60d5562421" . "6a008453c89" . "0fdf17e4fbe"] . $event->getPreviousStatusName() . $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_cf4d8ef1a5059866b44a176b7f8" . "89003"] . $event->getStatusName() . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_e608e5b5c4c34a67ba" . "97ef84c1e16199"], $context);
            } else {
                $this->logger->error($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_3ef2817" . "0d0a5fc2" . "4f9612e5" . "b65d09b4" . "c"] . $code . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_0eaf2641d2" . "0998e3cd9d5" . "23a60dd1f3c"] . $event->getIntendedStatusName() . $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_e608e5b5c4c34a67ba97" . "ef84c1e16199"], $context);
            }
            
            
            if (isset($_c35473364fa7a050299058f332ec29c1)) {
                if ($_c35473364fa7a050299058f332ec29c1 instanceof PluginsConfigException) {
                    throw $_c35473364fa7a050299058f332ec29c1;
                }
                
                
                throw PluginsConfigException::unexpectedError($code, $_6c40c95e1e1917386016d93d6261f85d, $_c35473364fa7a050299058f332ec29c1);
            }
            return $event;
        }
    }
}