<?php
namespace Claromentis\Core\Plugin;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"] = (@$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"] ?: array()) + array("st" . "at" . "us" => base64_decode("c3R" . "hdH" . "Vz"), "co" . "de" => base64_decode("Y29kZQ" . "=="), "_cf4d8ef1a5059866b44a176b7" . "f889003" => base64_decode("JyB" . "0by" . "An"), "_3ef28170d0a5fc24f9" . "612e5b65d09b4c" => base64_decode("RXJyb3IgdXBkYXRpbmcgJw" . "=="), "_d0845bf" . "f5cd0ddb" . "5ed1d7bd" . "9db996f5" . "1" => base64_decode("c29" . "1cm" . "Nl"), "_c87518f15b2c098ea49" . "8f3404e7d3ff9" => base64_decode("cHJldmlvdXNT" . "dGF0dXM="), "_60d55624216a008453c8" . "90fdf17e4fbe" => base64_decode("JyBwbHVnaW4gc3RhdHVzIHVwZGF0ZW" . "QgZnJvbSAn"), "_c51bc96058fbdbf4c2ef19b306d1a1" . "24" => base64_decode("Y2xhc3N" . "fZXhpc3" . "Rz"), "_ea8229a121285ee649a72fd880" . "bac39b" => base64_decode("YXJyYXlfZmls" . "dGVy"), "_c35473364fa7a050299058f" . "332ec29c1" => base64_decode("ZXhj" . "ZXB0" . "aW9u"), "_0eaf2641d20998e3cd" . "9d523a60dd1f3c" => base64_decode("JyBwbHVnaW4gc3RhdHVzI" . "HRvICc="), "_35ed77cc" . "ccaf3a056" . "dcf16acae" . "33bbe0" => base64_decode("Y2xhc3" . "M="), "_6c40c95e1e1917386" . "016d93d6261f85d" => base64_decode("aW50ZW5k" . "ZWRTdGF0" . "dXM="), "_e608e5b5c" . "4c34a67ba9" . "7ef84c1e16" . "199" => base64_decode("Jw" . "=="));
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["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_35ed77ccccaf3a" . "056dcf16acae33b" . "be0"]]) && $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_c51bc96058fbdb" . "f4c2ef19b306d1a" . "124"]($_6aead4bff5639b251aebcf8a630e43a7[$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_35ed77ccccaf3a05" . "6dcf16acae33bbe0"]]);
    }
    
    
    
    
    
    
    
    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($_2cf093f28f4c7e718a5e8af628894c7b, $event);
            $context = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_ea8229a121285e" . "e649a72fd880bac" . "39b"]([$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["cod" . "e"] => $event->getCode(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["st" . "at" . "us"] => $event->getStatusName(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_c87518f15b2c" . "098ea498f3404" . "e7d3ff9"] => $event->getPreviousStatusName(), $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_6c40c95e" . "1e1917386" . "016d93d62" . "61f85d"] => $event->getIntendedStatusName(), $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_d0845bff5cd0ddb5ed1d7bd9d" . "b996f51"] => $event->getSource(), $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_c35473364fa7a05" . "0299058f332ec29c" . "1"] => $event->getThrowable()]);
            if ($event->success()) {
                $this->logger->notice($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_e608e5b5c4c34a67ba97ef84c" . "1e16199"] . $code . $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_60d5562" . "4216a008" . "453c890f" . "df17e4fb" . "e"] . $event->getPreviousStatusName() . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_cf4d8ef1a5059866b44" . "a176b7f889003"] . $event->getStatusName() . $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_e608e5b5c" . "4c34a67ba9" . "7ef84c1e16" . "199"], $context);
            } else {
                $this->logger->error($GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_3ef28170d0a5fc24f9612e5b65d09" . "b4c"] . $code . $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_0eaf2641d20998" . "e3cd9d523a60dd1" . "f3c"] . $event->getIntendedStatusName() . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_e608e5b5c4c34a67ba97ef84c1e16" . "199"], $context);
            }
            
            
            if (isset($_c35473364fa7a050299058f332ec29c1)) {
                if ($_c35473364fa7a050299058f332ec29c1 instanceof PluginsConfigException) {
                    throw $_c35473364fa7a050299058f332ec29c1;
                }
                
                
                throw PluginsConfigException::unexpectedError($code, $_6c40c95e1e1917386016d93d6261f85d, $_c35473364fa7a050299058f332ec29c1);
            }
            return $event;
        }
    }
}