<?php
namespace Claromentis\Setup\Task;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"] ?: array()) + array("_dcf86ccc31af7f63a" . "f36115aa12b1ee7" => base64_decode("Y2" . "hk" . "aX" . "I="), "_9342063570b40df2075204394b59df5" . "9" => base64_decode("Z2V0" . "Y3dk"), "_a591754a8ddcdbda9c80f1db4d911" . "e14" => base64_decode("aXNfbnV" . "sbA=="));
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["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_a591754a8ddcdbda" . "9c80f1db4d911e14"]($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"]["_9342063570b40" . "df2075204394b5" . "9df59"]();
        $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_dcf86ccc31af7f" . "63af36115aa12b1" . "ee7"]($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["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_dcf86ccc3" . "1af7f63af3" . "6115aa12b1" . "ee7"]($_3e91a953f0ae44bc853e303c034f9d93);
    }
    
    
    
    
    
    
    public function Install()
    {
        
        
        $this->InstallSchema();
        
        
        $this->InitApplication();
    }
    
    
    
    
    
    
    public function Update()
    {
        $_3e91a953f0ae44bc853e303c034f9d93 = $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_9342063570b40df2075204394b59df5" . "9"]();
        $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_dcf86ccc31af7f63af36115aa12b1e" . "e7"]($this->getApplicationPath());
        
        
        $this->schema->Update();
        $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_dcf86ccc31af7f63af36115aa12b1" . "ee7"]($_3e91a953f0ae44bc853e303c034f9d93);
    }
    
    
    
    
    
    
    protected function SchemaIsCreated()
    {
        return $this->persistence->GetVersion() !== null;
    }
}