<?php
namespace Claromentis\Setup\Task;

$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"] = (@$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"] ?: array()) + array("_a591754a8ddcdbda9c80f1db4d" . "911e14" => base64_decode("aXNfbnVsbA=" . "="), "_dcf86ccc31af7f63af36115aa12" . "b1ee7" => base64_decode("Y2h" . "kaX" . "I="), "_9342063570b40df2075204394" . "b59df59" => base64_decode("Z2V0Y" . "3dk"));
use Claromentis\Core\DAL\Interfaces\SchemaInterface;
use Claromentis\Setup\Db\SchemaFacade;
use Claromentis\Setup\Logger;
use Claromentis\Setup\Db\Migrations;
use Claromentis\Setup\Script\Init;
use Claromentis\Setup\SetupFacade;
use Psr\Log\LoggerInterface;






class Install
{
    
    
    
    
    protected $db;
    
    
    
    
    protected $schema;
    
    
    
    
    protected $logger;
    
    
    
    
    protected $persistence;
    
    
    
    
    
    
    protected $application;
    
    
    
    
    
    
    protected $application_path;
    
    
    
    
    protected $properties;
    
    
    
    
    
    
    
    
    
    public function __construct($db, $_2d854c635c08f7a0d7b28391f0fb5bfd, $_4825e032d19ebe3edee32a6a54c7afd2, Migrations\Persistence $_d3a4df576cec8d467e29e06a95ac4009 = null)
    {
        $this->db = $db;
        $this->application = $_2d854c635c08f7a0d7b28391f0fb5bfd;
        $this->application_path = $_4825e032d19ebe3edee32a6a54c7afd2;
        $this->persistence = $_d3a4df576cec8d467e29e06a95ac4009;
        if ($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_a591754a8ddcdbda9c80f" . "1db4d911e14"]($this->persistence)) {
            $this->persistence = new Migrations\PersistenceDatabase($_2d854c635c08f7a0d7b28391f0fb5bfd, $this->db);
        }
        $this->schema = new SchemaFacade($this->db, $_2d854c635c08f7a0d7b28391f0fb5bfd, $_4825e032d19ebe3edee32a6a54c7afd2, $_d3a4df576cec8d467e29e06a95ac4009);
        $this->setLogger(new Logger());
    }
    
    
    
    
    
    
    public function getApplicationCode()
    {
        return $this->application;
    }
    
    
    
    
    
    
    public function getApplicationPath()
    {
        return $this->application_path;
    }
    
    
    
    
    
    
    public function setLogger(LoggerInterface $logger)
    {
        $this->logger = $logger;
        $this->schema->setLogger($this->logger);
        $this->persistence->setLogger($this->logger);
    }
    
    
    
    
    
    
    public function setProperties(array $_809a58dc73011173c031a53c0b40ef0e)
    {
        $this->properties = $_809a58dc73011173c031a53c0b40ef0e;
    }
    
    
    
    
    
    
    public function InstallSchema()
    {
        
        
        $this->schema->Install();
    }
    
    
    
    
    
    
    protected function InitApplication()
    {
        $_3e91a953f0ae44bc853e303c034f9d93 = $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_9342063570b40df2075204394b59df5" . "9"]();
        $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_dcf86ccc31af7f63af36115aa" . "12b1ee7"]($this->getApplicationPath());
        $_45f9b20d836bf913104678193ccc4814 = new SetupFacade($this->db);
        $_45f9b20d836bf913104678193ccc4814->setLogger($this->logger);
        $_45f9b20d836bf913104678193ccc4814->SetProperties($this->properties);
        $_0ab271f12643b1e576aa1bc6db54cb4e = new Init($this->application_path);
        $_0ab271f12643b1e576aa1bc6db54cb4e->Run($_45f9b20d836bf913104678193ccc4814);
        $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_dcf86ccc31af7f63af36115" . "aa12b1ee7"]($_3e91a953f0ae44bc853e303c034f9d93);
    }
    
    
    
    
    
    
    public function Install()
    {
        
        
        $this->InstallSchema();
        
        
        $this->InitApplication();
    }
    
    
    
    
    
    
    public function Update()
    {
        $_3e91a953f0ae44bc853e303c034f9d93 = $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_9342063570b40df2075204" . "394b59df59"]();
        $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_dcf86ccc31af7f63af36115aa12" . "b1ee7"]($this->getApplicationPath());
        
        
        $this->schema->Update();
        $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_dcf86ccc31af7f63" . "af36115aa12b1ee7"]($_3e91a953f0ae44bc853e303c034f9d93);
    }
    
    
    
    
    
    
    protected function SchemaIsCreated()
    {
        return $this->persistence->GetVersion() !== null;
    }
}