<?php

use Psr\Container\ContainerInterface;

return [
    Incoviba\Service\Login::class => function(ContainerInterface $container) {
        return new Incoviba\Service\Login(
            $container->get(Incoviba\Repository\Login::class),
            $container->get(Incoviba\Repository\User::class),
            $container->get('COOKIE_NAME'),
            $container->get('MAX_LOGIN_HOURS'),
            $container->has('COOKIE_DOMAIN') ? $container->get('COOKIE_DOMAIN') : '',
            $container->has('COOKIE_PATH') ? $container->get('COOKIE_PATH') : '',
            $container->has('COOKIE_SEPARATOR') ? $container->get('COOKIE_SEPARATOR') : 'g'
        );
    },
    Incoviba\Service\Money::class => function(ContainerInterface $container) {
        $mindicador = new Incoviba\Service\Money\MiIndicador(new GuzzleHttp\Client([
            'base_uri' => 'https://mindicador.cl/api/',
            'headers' => ['Accept' => 'application/json']
        ]));
        $ine = new Incoviba\Service\Money\Ine(new GuzzleHttp\Client([
            'base_uri' => 'https://api-calculadora.ine.cl/ServiciosCalculadoraVariacion'
        ]));
        return (new Incoviba\Service\Money($container->get(Psr\Log\LoggerInterface::class)))
            ->register('uf', $mindicador)
            ->register('usd', $mindicador)
            ->register('ipc', $ine);
    },
    Predis\ClientInterface::class => function(ContainerInterface $container) {
        $options = [
            'scheme' => 'tcp',
            'host' => $container->get('REDIS_HOST'),
            'port' => $container->get('REDIS_PORT')
        ];
        if ($container->has('REDIS_USER')) {
            $options['username'] = $container->get('REDIS_USER');
        }
        if ($container->has('REDIS_PASSWORD')) {
            $options['password'] = $container->get('REDIS_PASSWORD');
        }
        return new Predis\Client($options);
    },
    Incoviba\Service\Contabilidad\Cartola::class => function(ContainerInterface $container) {
        return (new Incoviba\Service\Contabilidad\Cartola(
            $container->get(Psr\Log\LoggerInterface::class),
            $container->get(Psr\Http\Message\StreamFactoryInterface::class),
            $container->get(Incoviba\Common\Define\Contabilidad\Exporter::class),
            $container->get(Incoviba\Repository\Inmobiliaria::class),
            $container->get(Incoviba\Repository\Inmobiliaria\Cuenta::class),
            $container->get(Incoviba\Repository\Contabilidad\Movimiento::class),
            $container->get(Incoviba\Service\Contabilidad\Movimiento::class),
            $container->get(Incoviba\Repository\Contabilidad\Cartola::class)
        ))
            ->register('security', $container->get(Incoviba\Service\Contabilidad\Cartola\Security::class))
            ->register('itau', $container->get(Incoviba\Service\Contabilidad\Cartola\Itau::class))
            ->register('santander', $container->get(Incoviba\Service\Contabilidad\Cartola\Santander::class))
            ->register('bci', $container->get(Incoviba\Service\Contabilidad\Cartola\BCI::class));
    },
    Incoviba\Common\Define\Contabilidad\Exporter::class => function(ContainerInterface $container) {
        return $container->get(Incoviba\Service\Contabilidad\Exporter\Nubox::class);
    },
    Incoviba\Service\Contabilidad\Exporter\Nubox::class => function(ContainerInterface $container) {
        return new Incoviba\Service\Contabilidad\Exporter\Nubox($container->get(Incoviba\Repository\Contabilidad\CentroCosto::class),
            $container->get('folders')->get('uploads'));
    },
    Incoviba\Service\Contabilidad\Nubox::class => function(ContainerInterface $container) {
        return new Incoviba\Service\Contabilidad\Nubox(
            $container->get(Psr\Log\LoggerInterface::class),
            $container->get(Incoviba\Repository\Contabilidad\Nubox::class),
            $container->get(Incoviba\Service\Redis::class),
            new GuzzleHttp\Client([
                'defaults' => [
                    'config' => [
                        'curl' => [
                            CURLOPT_SSL_VERIFYPEER => false,
                            CURLOPT_SSL_VERIFYHOST => false,
                            CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1_3
                        ],
                        'verify' => false
                    ]
                ],
            ]),
            $container->get(Psr\Http\Message\RequestFactoryInterface::class),
            $container->get('nubox')->get('url'));
    },
    Incoviba\Service\Informe::class => function(ContainerInterface $container) {
        return (new Incoviba\Service\Informe(
            $container->get(Psr\Log\LoggerInterface::class),
            $container->get('folders')->get('informes'))
        )
            ->register('xlsx', Incoviba\Service\Informe\Excel::class);
    },
    Incoviba\Service\Contabilidad\Informe\Tesoreria\Output\Excel::class => function(ContainerInterface $container) {
        return new Incoviba\Service\Contabilidad\Informe\Tesoreria\Output\Excel(
            $container->get(Psr\Log\LoggerInterface::class),
            $container->get('folders')->get('informes'),
            $container->get(Incoviba\Service\UF::class),
            $container->get(Incoviba\Service\USD::class)
        );
    },
    Incoviba\Service\Contabilidad\Cartola\Santander::class => function(ContainerInterface $container) {
        return (new Incoviba\Service\Contabilidad\Cartola\Santander(
            $container->get(Psr\Log\LoggerInterface::class),
        ))
            ->registerSub($container->get(Incoviba\Service\Contabilidad\Cartola\Santander\OfficeBanking::class));
    },
    Incoviba\Service\Contabilidad\Cartola\BCI::class => function(ContainerInterface $container) {
        return (new Incoviba\Service\Contabilidad\Cartola\BCI(
            $container->get(Psr\Log\LoggerInterface::class),
        ))
            ->registerSub($container->get(Incoviba\Service\Contabilidad\Cartola\BCI\Mes::class));
    }
];
