<?php

declare(strict_types=1);

namespace UtilityModule;

use Tuupola\Middleware\CorsMiddleware;
use Tuupola\Middleware\JwtAuthentication;
use Zend\EventManager\EventManager;

/**
 * The configuration provider for the DoctrineExpressiveModule module
 *
 * @see https://docs.zendframework.com/zend-component-installer/
 */
class ConfigProvider
{
    /**
     * Returns the configuration array
     *
     * To add a bit of a structure, each section is defined in a separate
     * method which returns an array with its configuration.
     *
     */
    public function __invoke() : array
    {
        return [
            'dependencies' => $this->getDependencies(),
            'form_elements' => $this->getFormElements(),
            'console' => $this->getConsoleCommands(),
        ];
    }

    /**
     * Returns the container dependencies
     */
    public function getDependencies() : array
    {
        return [
            'aliases' => [
                'doctrine.hydrator' => Hydrator\DoctrineObject::class,
                'EventManager' => EventManager::class,
            ],
            'invokables' => [
                EventManager::class => EventManager::class,
            ],
            'factories'  => [
                Command\GeneratePasswordHash::class => Command\GeneratePasswordHashFactory::class,

                Hydrator\DoctrineObject::class => Hydrator\DoctrineObjectFactory::class,

                CorsMiddleware::class => Middleware\CorsMiddlewareFactory::class,
                JwtAuthentication::class => Middleware\JwtMiddlewareFactory::class,

                Handler\AuthHandler::class => Handler\AuthHandlerFactory::class,
                Service\AuthService::class => Service\AuthServiceFactory::class,
            ],
        ];
    }

    /**
     * Returns the form dependencies
     */
    public function getFormElements() : array
    {
        return [
            'aliases' => [
                'doctrine.object_select' => Form\Element\ObjectSelect::class,
            ],
            'factories'  => [
                Form\Element\ObjectSelect::class => Form\Element\ElementFactory::class,
            ],
        ];
    }

    public function getConsoleCommands(): array
    {
        return [
            'commands' => [
                Command\GeneratePasswordHash::class,
            ]
        ];
    }
}
