<?php
namespace Claromentis\Setup\Task;

$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"] = (@$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"] ?: array()) + array("_a591754a8ddcdbda9c80f1db4d911" . "e14" => base64_decode("aXNfb" . "nVsbA" . "=="), "_dcf86ccc31af7f63af36115aa12" . "b1ee7" => base64_decode("Y2hk" . "aXI="), "_9342063570b40df2075204394b59df" . "59" => 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["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_a591754a8ddcdbda9c" . "80f1db4d911e14"]($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"]["_9342063570b4" . "0df2075204394" . "b59df59"]();
        $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_dcf86ccc31" . "af7f63af361" . "15aa12b1ee7"]($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["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_dcf86ccc31af7f63af36" . "115aa12b1ee7"]($_3e91a953f0ae44bc853e303c034f9d93);
    }
    
    
    
    
    
    
    public function Install()
    {
        
        
        $this->InstallSchema();
        
        
        $this->InitApplication();
    }
    
    
    
    
    
    
    public function Update()
    {
        $_3e91a953f0ae44bc853e303c034f9d93 = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_9342063570b40df2075204394b59d" . "f59"]();
        $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_dcf86ccc31af7f63af36115aa1" . "2b1ee7"]($this->getApplicationPath());
        
        
        $this->schema->Update();
        $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_dcf86ccc" . "31af7f63a" . "f36115aa1" . "2b1ee7"]($_3e91a953f0ae44bc853e303c034f9d93);
    }
    
    
    
    
    
    
    protected function SchemaIsCreated()
    {
        return $this->persistence->GetVersion() !== null;
    }
}