<?php

declare(strict_types=1);

namespace Application;

use Application\Controller\CmController;
use Application\Controller\DashboardController;
use Application\Controller\ExposeController;
use Application\Controller\FieldController;
use Application\Controller\FormController;
use Application\Controller\FormgroupController;
use Application\Controller\LogController;
use Application\Controller\LogicController;
use Application\Controller\PatientH5Controller;
use Application\Controller\project\ae\AeController;
use Application\Controller\project\ItemPhotoController;
use Application\Controller\project\SaeController;
use Application\Controller\SasController;
use Application\Controller\Temple\ChecklistController;
use Application\Controller\ThirdController;
use Application\Controller\v2\ItemFieldController;
use Application\Controller\WechatController;
use Application\Factory\ServiceFactory;
use Application\Mvc\Controller\Plugins\LocalService;
use Application\Mvc\Controller\Plugins\RenderApiJson;
use Application\Service\Extension\Helper\ArrayHelper;
use Laminas\ServiceManager\Factory\InvokableFactory;
use Project\Controller\AeresultController;

$routes = include 'routes/v1.php';
$routesV2 = include 'routes/v2.php';
$dashboardRoutes = include 'routes/dashboard.php';

// 这里的路由会自动注册controller
$mainRoutes = include 'routes/main.php';

$allRoutes = [];
foreach ([$routes, $routesV2, $dashboardRoutes, $mainRoutes->getRoutes()] as $route) {
    $allRoutes = ArrayHelper::merge($allRoutes, $route);
}

return [
    'router' => [
        'routes' => $allRoutes
    ],
    'controllers'  => [
        'factories' => ArrayHelper::merge([
            Controller\IndexController::class => InvokableFactory::class,
            Controller\LoginController::class => InvokableFactory::class,
            Controller\CommonController::class => InvokableFactory::class,
            FormController::class => InvokableFactory::class,
            FieldController::class => InvokableFactory::class,
            \Application\Controller\item\FormController::class => InvokableFactory::class,
            \Application\Controller\item\FieldController::class => InvokableFactory::class,
            FormgroupController::class => InvokableFactory::class,
            \Application\Controller\item\patient\FormController::class => InvokableFactory::class,
            ItemPhotoController::class => InvokableFactory::class,
            \Project\Controller\ItemphotoController::class => InvokableFactory::class,
            AeController::class => InvokableFactory::class,
            AeresultController::class => InvokableFactory::class,
            \Application\Controller\item\QuestionController::class => InvokableFactory::class,
            \Application\Controller\CrontabController::class => InvokableFactory::class,
            SaeController::class => InvokableFactory::class,
            WechatController::class => InvokableFactory::class,
            LogicController::class => InvokableFactory::class,
            ExposeController::class => InvokableFactory::class,
            SasController::class => InvokableFactory::class,
            DashboardController::class => InvokableFactory::class,
            CmController::class => InvokableFactory::class,
            ChecklistController::class => InvokableFactory::class,
            PatientH5Controller::class => InvokableFactory::class,
            LogController::class => InvokableFactory::class,
            ItemFieldController::class => InvokableFactory::class,
            ThirdController::class => InvokableFactory::class,
        ], $mainRoutes->getControllers()),
    ],
    'controller_plugins' => [
        'aliases' => [
            'LocalService' => LocalService::class,
            'RenderApiJson' => RenderApiJson::class,
        ],
        'factories' => [
            LocalService::class => ServiceFactory::class,
            RenderApiJson::class => InvokableFactory::class,
        ],
    ],
    'service_manager' => include __DIR__."/service.config.php",
    'laminas-cli' => include __DIR__.'/cli/laminasCli.config.php',
    'view_manager' => [
        'display_not_found_reason' => true,
        'display_exceptions'       => true,
        'doctype'                  => 'HTML5',
        'not_found_template'       => 'error/404',
        'exception_template'       => 'error/index',
        'template_map'             => [
            'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
            'layout/dashboardLayout'           => __DIR__ . '/../view/layout/dashboardLayout.phtml',
            'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
            'error/404'               => __DIR__ . '/../view/error/404.phtml',
            'error/index'             => __DIR__ . '/../view/error/index.phtml',
        ],
        'template_path_stack'      => [
            __DIR__ . '/../view',
        ],
    ],
];
