<?php
namespace Claromentis\Console\Util;

$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"] = (@$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"] ?: array()) + array("_4c93d4c40f7a" . "b1a488c387f7f" . "91a6496" => base64_decode("Q2hlY2tpbmc" . "gaW5zdGFsbG" . "F0aW9uLi4u"), "_5bcefc1eff68a2aa" . "6ab8f35699a56d08" => base64_decode("RGF0YWJhc2UgaXMgbm90" . "IGF2YWlsYWJsZTog"), "_3e09962b663b985bf" . "8c260ac2e95edc0" => base64_decode("Y29yZQ=" . "="), "_77713ce2368" . "3636d0573408" . "c9a0d0ddb" => base64_decode("RGF0YWJhc2UgcGVybWlzc2lvbnMgYXJlIGFkZXF1" . "YXRl"), "_1094b976516d8df54067d" . "448e66e0297" => base64_decode("RGF0YWJh" . "c2UgaXMg" . "YXZhaWxh" . "Ymxl"), "_a70083b91f8d" . "3b0237061e068" . "26958e8" => base64_decode("Q2hlY2tpbmcgZGF0YWJhc2UgYX" . "ZhaWxhYmlsaXR5Li4u"), "_7b2ca9a105acfcc088d2c15bfe645" . "8b6" => base64_decode("Q29yZSBpcyBub" . "3QgaW5zdGFsbG" . "Vk"), "_9636e44" . "5fbeaa4b" . "bfe5694e" . "d532de0b" . "1" => base64_decode("RGF0YWJhc2UgcGV" . "ybWlzc2lvbnMgaW" . "5zdWZmaWNpZW50"), "_9810a2810" . "274128200c" . "b24f15909a" . "3f2" => base64_decode("Q2hlY2tpbmcg" . "ZGF0YWJhc2Ug" . "cGVybWlzc2lv" . "bnMuLi4="));
use Claromentis\Core\Config\Config;
use Claromentis\Core\DAL\DbFactory;
use Claromentis\Core\Module;
use Claromentis\Setup\Exception\NotInstalledException;
use Claromentis\Setup\Task\DatabaseCheck;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\NullLogger;
use RuntimeException;




class InstallationChecker implements LoggerAwareInterface
{
    use LoggerAwareTrait;
    protected Config $config;
    protected DbFactory $factory;
    protected Locator $locator;
    protected Module\Api $modules;
    
    
    
    
    
    
    
    
    
    public function __construct(Config $_fd33b1a14db9a1eccfaaa3cb67b5336e, DbFactory $_c8ef295ed962a46e6246480731bf7b99, Locator $_958a49c0e9814c5c29eb8698e3fb6de2, Module\Api $_59eea0afb98cc6c83c49d730362a45fd)
    {
        $this->config = $_fd33b1a14db9a1eccfaaa3cb67b5336e;
        $this->factory = $_c8ef295ed962a46e6246480731bf7b99;
        $this->locator = $_958a49c0e9814c5c29eb8698e3fb6de2;
        $this->modules = $_59eea0afb98cc6c83c49d730362a45fd;
        $this->setLogger(new NullLogger());
    }
    
    
    
    
    
    
    public function isInstalled()
    {
        try {
            $this->logger->info($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_4c93d4c40f7ab1a488c387f7f9" . "1a6496"]);
            $this->verifyInstalled();
        } catch (\Exception $_c35473364fa7a050299058f332ec29c1) {
            return false;
        }
        return true;
    }
    
    
    
    
    
    
    public function checkDatabaseConnection()
    {
        try {
            $this->logger->info($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_a70083b91" . "f8d3b02370" . "61e0682695" . "8e8"]);
            $this->verifyDatabaseConnection();
            $this->logger->debug($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_1094b9765" . "16d8df5406" . "7d448e66e0" . "297"]);
        } catch (\Exception $_c35473364fa7a050299058f332ec29c1) {
            
            
            
            $this->logger->info($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_5bcefc1eff68a2aa6" . "ab8f35699a56d08"] . $_c35473364fa7a050299058f332ec29c1->getMessage());
            return false;
        }
        return true;
    }
    
    
    
    
    
    
    public function checkDatabasePermissions()
    {
        try {
            $this->logger->info($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_9810a2810274128200cb24f15909" . "a3f2"]);
            $this->verifyDatabasePermissions();
            $this->logger->debug($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_77713ce23" . "683636d057" . "3408c9a0d0" . "ddb"]);
        } catch (\Exception $_c35473364fa7a050299058f332ec29c1) {
            
            
            return false;
        }
        return true;
    }
    
    
    
    
    
    
    
    public function verifyInstalled()
    {
        $this->verifyDatabaseConnection();
        $this->verifyDatabasePermissions();
        if (!$this->modules->isInstalled($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_3e09962b663b9" . "85bf8c260ac2e9" . "5edc0"])) {
            throw new NotInstalledException($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_7b2ca9a105ac" . "fcc088d2c15bf" . "e6458b6"]);
        }
    }
    
    
    
    
    
    
    
    public function verifyDatabaseConnection()
    {
        
        
        $_4504853ce5094b088c8bdc3d570a0a5d = $this->getDatabase();
        
        
        $this->modules->setDatabase($_4504853ce5094b088c8bdc3d570a0a5d);
    }
    
    
    
    
    
    
    
    public function verifyDatabasePermissions()
    {
        $_4504853ce5094b088c8bdc3d570a0a5d = $this->getDatabase();
        $_58bc0ced402c33be307fe4d3d5433ed1 = new DatabaseCheck($this->config, $_4504853ce5094b088c8bdc3d570a0a5d);
        $_58bc0ced402c33be307fe4d3d5433ed1->setLogger($this->logger);
        if (!$_58bc0ced402c33be307fe4d3d5433ed1->Check()) {
            foreach ($_58bc0ced402c33be307fe4d3d5433ed1->GetErrors() as $_ba3845cb79c005cf3269af8c83ddbe5e) {
                $this->logger->error($_ba3845cb79c005cf3269af8c83ddbe5e);
            }
            throw new RuntimeException($GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_9636e445fbeaa4bbfe5694ed532de0" . "b1"]);
        }
    }
    
    
    
    
    
    
    
    protected function getDatabase()
    {
        return $this->factory->GetInstanceFromConfig($this->config);
    }
}