#!/usr/bin/php
<?php

declare(strict_types=1);

namespace Php\Pie;

use Php\Pie\Command\BuildCommand;
use Php\Pie\Command\InstallExtensionsForProjectCommand;
use Php\Pie\Command\DownloadCommand;
use Php\Pie\Command\InfoCommand;
use Php\Pie\Command\InstallCommand;
use Php\Pie\Command\RepositoryAddCommand;
use Php\Pie\Command\RepositoryListCommand;
use Php\Pie\Command\RepositoryRemoveCommand;
use Php\Pie\Command\SelfUpdateCommand;
use Php\Pie\Command\SelfVerifyCommand;
use Php\Pie\Command\ShowCommand;
use Php\Pie\Command\UninstallCommand;
use Php\Pie\Util\PieVersion;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\CommandLoader\ContainerCommandLoader;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;

error_reporting(error_reporting() & ~E_DEPRECATED);

/** @psalm-suppress UnresolvableInclude */
include $_composer_autoload_path ?? '/usr/share/pie/vendor/autoload.php';

$container = Container::factory();

$application = new Application('🥧 PHP Installer for Extensions (PIE)', PieVersion::get());

$application->setDispatcher($container->get(EventDispatcher::class));

$application->setCommandLoader(new ContainerCommandLoader(
    $container,
    [
        'download' => DownloadCommand::class,
        'build' => BuildCommand::class,
        'install' => InstallCommand::class,
        'info' => InfoCommand::class,
        'show' => ShowCommand::class,
        'repository:list' => RepositoryListCommand::class,
        'repository:add' => RepositoryAddCommand::class,
        'repository:remove' => RepositoryRemoveCommand::class,
        'uninstall' => UninstallCommand::class,
        'self-update' => SelfUpdateCommand::class,
        'self-verify' => SelfVerifyCommand::class,
        'install-extensions-for-project' => InstallExtensionsForProjectCommand::class,
    ]
));

$application->run($container->get(InputInterface::class), $container->get(OutputInterface::class));
