<?php

namespace ModulesGarden\Servers\OpenXchange\Core\App\Installer;

use ModulesGarden\Servers\OpenXchange\Core\App\Packages\PackageManager;
use ModulesGarden\Servers\OpenXchange\Core\DependencyInjection;
use ModulesGarden\Servers\OpenXchange\Core\ModuleConstants;

class ModuleInstaller
{
    protected $databaseInstaller = null;

    public function __construct()
    {
        $this->databaseInstaller = DependencyInjection::get(DatabaseInstaller::class);
    }

    public function makeInstall()
    {
        $this->installModule();
    }

    public function installModule()
    {
        array_map(function ($value){
            $this->databaseInstaller->performQueryFromFile($value);
        }, $this->getModuleQueriesPaths());
    }

    public function getModuleQueriesPaths()
    {
        return [
            ModuleConstants::getFullPath('core', 'Database', 'schema.sql'),
            ModuleConstants::getFullPath('app', 'Database', 'schema.sql'),
            ModuleConstants::getFullPath('core', 'Database', 'data.sql'),
            ModuleConstants::getFullPath('app', 'Database', 'data.sql')
        ];
    }
    
    public function isInstallCorrect()
    {
        return $this->databaseInstaller->isInstallCorrect();
    }

    public function getFailedQueries()
    {
        return $this->databaseInstaller->getFailedQueries();
    }

    public function getQueriesResults()
    {
        return $this->databaseInstaller->getQueriesResults();
    }
}
