#!/usr/bin/env php
<?php

use Bdf\Instantiator\Instantiator;
use Bdf\Instantiator\InstantiatorInterface;
use Bdf\Queue\Consumer\Receiver\Builder\ReceiverLoader;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\DumpCompletionCommand;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;

if (file_exists($autoloadFile = __DIR__.'/../vendor/autoload.php') || file_exists($autoloadFile = __DIR__.'/../../../autoload.php')) {
    require $autoloadFile;
}
require __DIR__.'/lib/services.php';
require __DIR__.'/lib/console.php';
require __DIR__.'/lib/psr.php';

ini_set('display_errors', 1);
error_reporting(E_ALL);

$container = new Container();
$container->set(LoggerInterface::class, new Logger());
$container->set(InstantiatorInterface::class, new Instantiator($container));

$driverFactory = getConnectionsDriverFactory();
$destinationManager = getDestinationManager();
$loader = new ReceiverLoader($container, require __DIR__.'/config/receivers.php');

$console = new \Symfony\Component\Console\Application();
$console->add(new Bdf\Queue\Console\Command\InfoCommand($driverFactory));
$console->add(new Bdf\Queue\Console\Command\BindCommand($driverFactory));
$console->add(new Bdf\Queue\Console\Command\ProduceCommand($destinationManager));
$console->add(new Bdf\Queue\Console\Command\SetupCommand($destinationManager));
$console->add(new Bdf\Queue\Console\Command\ConsumeCommand($destinationManager, $loader));

$failer = getFailerStorage();
$console->add(new Bdf\Queue\Console\Command\Failer\DeleteCommand($failer));
$console->add(new Bdf\Queue\Console\Command\Failer\RetryCommand($failer, $destinationManager));
$console->add(new Bdf\Queue\Console\Command\Failer\ShowCommand($failer));

$console->add(new DumpCompletionCommand());

$input = new ArgvInput();
$output = new ConsoleOutput(ConsoleOutput::VERBOSITY_DEBUG);
$console->run($input, $output);
