#!/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\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;

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

$container = Container::factory();

$pieAppName = '🥧 PHP Installer for Extensions (PIE)';
$pieVersion = PieVersion::get();
$application = new Application($pieAppName, $pieVersion);
echo $pieAppName . ', ' . $pieVersion . ", from The PHP Foundation\n";

$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,
        'install-extensions-for-project' => InstallExtensionsForProjectCommand::class,
    ]
));

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