<?php
use Psr\Container\ContainerInterface;

return [
    Incoviba\Service\Login::class => function(ContainerInterface $container) {
        $client = new GuzzleHttp\Client([
            'base_uri' => $container->get('API_URL'),
            'headers' => [
                'Authorization' => [
                    'Bearer ' . md5($container->get('API_KEY'))
                ]
            ]
        ]);
        return new Incoviba\Service\Login(
            $client,
            $container->get(Psr\Log\LoggerInterface::class),
            implode(DIRECTORY_SEPARATOR, [$container->get('folders')->cache, 'token']),
            $container->get('API_USERNAME'),
            $container->get('API_PASSWORD')
        );
    },
    Psr\Http\Client\ClientInterface::class => function(ContainerInterface $container) {
        $login = $container->get(Incoviba\Service\Login::class);
        return new GuzzleHttp\Client([
            'base_uri' => $container->get('API_URL'),
            'headers' => [
                'Authorization' => [
                    "Bearer {$login->getKey($container->get('API_KEY'))}"
                ]
            ]
        ]);
    }
];
