<?php

use Psr\Container\ContainerInterface;

return [
    Psr\Log\LoggerInterface::class => function(ContainerInterface $container) {
        return new Monolog\Logger('cli', [
            new Monolog\Handler\FilterHandler(new Monolog\Handler\RotatingFileHandler('/logs/cli.debug.log'), Monolog\Level::Debug, Monolog\Level::Notice),
            new Monolog\Handler\FilterHandler(new Monolog\Handler\RotatingFileHandler('/logs/cli.error.log'), Monolog\Level::Warning)
        ], [
            new Monolog\Processor\PsrLogMessageProcessor(),
            new Monolog\Processor\IntrospectionProcessor(),
            new Monolog\Processor\MemoryUsageProcessor(),
            new Monolog\Processor\MemoryPeakUsageProcessor()
        ]);
    },
    GuzzleHttp\Client::class => function(ContainerInterface $container) {
        return new GuzzleHttp\Client([
            'base_uri' => "http://{$container->get(App\Service\Remote::class)->getIP()}:8008",
            'headers' => [
                'Accept' => 'application/json'
            ]
        ]);
    },
    \App\Alias\RemoteConnection::class => function(ContainerInterface $container) {
        return new \App\Alias\RemoteConnection();
    },
    App\Service\Remote::class => function(ContainerInterface $container) {
        return new App\Service\Remote($container->get(\App\Alias\RemoteConnection::class));
    },
    App\Service\Money::class => function(ContainerInterface $container) {
        return new App\Service\Money($container->get(GuzzleHttp\Client::class));
    },
    \App\Alias\Connection::class => function(ContainerInterface $container) {
        $data = $container->get('databases')->get(ORM::DEFAULT_CONNECTION);
        return new \App\Alias\Connection(
            $data->get('host'),
            $data->get('database'),
            $data->get('username'),
            $data->get('password'),
            $data->has('port') ? $data->get('port') : null
        );
    },
];
