<?php
namespace Claromentis\Setup\Task;

$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"] ?: array()) + array("_dcf86ccc31af7f63af" . "36115aa12b1ee7" => base64_decode("Y2hk" . "aXI="), "_9342063570b40df20752043" . "94b59df59" => base64_decode("Z2V" . "0Y3" . "dk"), "_a591754a8ddcdbda9c80f1db4d911e1" . "4" => base64_decode("aXNfbn" . "VsbA=="));
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["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_a591754" . "a8ddcdbd" . "a9c80f1d" . "b4d911e1" . "4"]($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["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_9342063570b40df2075204394b59" . "df59"]();
        $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_dcf86ccc31af7f63af36115aa12b1e" . "e7"]($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["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_dcf86ccc" . "31af7f63a" . "f36115aa1" . "2b1ee7"]($_3e91a953f0ae44bc853e303c034f9d93);
    }
    
    
    
    
    
    
    public function Install()
    {
        
        
        $this->InstallSchema();
        
        
        $this->InitApplication();
    }
    
    
    
    
    
    
    public function Update()
    {
        $_3e91a953f0ae44bc853e303c034f9d93 = $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_9342063570b40d" . "f2075204394b59d" . "f59"]();
        $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_dcf86ccc31af7f63af36115aa12b" . "1ee7"]($this->getApplicationPath());
        
        
        $this->schema->Update();
        $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_dcf86ccc31" . "af7f63af361" . "15aa12b1ee7"]($_3e91a953f0ae44bc853e303c034f9d93);
    }
    
    
    
    
    
    
    protected function SchemaIsCreated()
    {
        return $this->persistence->GetVersion() !== null;
    }
}