<?php
namespace install\services;

use \ILogger;
/**
 * Install service
 * @author Jérôme Brilland
 * @version 2.1
 * @copyright (c) 2019-2023, Jérôme Brilland
 * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License
 */
class Install {

    private $settings;

    public function __construct( array $databaseSettings, array $settings ) {
        \IoC::register( 'config', function() use ( $databaseSettings ) {
            return ['database' => $databaseSettings, 'log_level' => ILogger::ERROR];
        } );
        $this->settings = $settings;
    }

    public function perform( $listener ) {        
        $createDatabase = new CreateDatabase();
        $createDatabase->perform( $listener );

        $addSQLData = new AddSQLData( $this->settings );
        $addSQLData->perform( $listener );

        $writeConfigFile = new WriteConfigFile( \IoC::resolve( 'config' )['database'], $this->settings );
        $writeConfigFile->perform( $listener );
        
        $listener->installSucceeded();
    }

}
