<?php
    // Importa autoload do Composer
    require_once realpath(path: __DIR__ . '/../vendor/autoload.php');

    use AxiumPHP\AxiumPHP;
    use AxiumPHP\Core\Router;
    use Workbloom\Config\Config;
    use Workbloom\Component\Auth\v0\Middlewares\AuthMiddleware;

    // ============================
    // Configurações globais
    // ============================
    $Config = Config::getInstance();

    // ============================
    // Inicializa AxiumPHP com configs
    // ============================
    $axiumPHP = new AxiumPHP(config: [
        'errors' => [
            'display_errors' => 1,
            'display_startup_errors' => 1,
            'log_errors' => 1,
            'error_log' => realpath(path: __DIR__ . '/../app/Storage/Logs/php-error.log'),
            'error_reporting' => E_ALL
        ],
        'constants' => [
            'ROUTER_MODE' => 'JSON', // JSON
            'APP_SYS_MODE' => 'DEV', // DEV | PROD
            'ROOT_SYSTEM_PATH' => realpath(path: __DIR__ . "/.."),
            'INI_SYSTEM_PATH' => realpath(path: __DIR__ . "/../app"),
            'MODULE_PATH' => realpath(path: __DIR__ . "/../app/Module"),
            'STORAGE_FOLDER_PATH' => realpath(path: __DIR__ . "/../app/Storage"),
            'COMPONENT_PATH' => realpath(path: __DIR__ . "/../app/Common/Component"),
            'ROUTER_ALLOWED_ORIGINS' => [
                '*'
            ]
        ],
        'system' => [
            'enable_session' => true,
            'default_timezone' => 'America/Fortaleza',
        ],
        'logger' => [
            'driver' => 'FILE',
            'logDir' => realpath(path: __DIR__ . '/../app/Storage/Logs')
        ]
    ]);

    // ============================
    // Carrega componentes
    // ============================
    require COMPONENT_PATH . "/Auth/bootstrap.php";

    // ============================================
    // Carrega módulos do sistema versão 0
    // ============================================
    Router::group(
        prefix: '/v0/module',
        callback: function() {
            require MODULE_PATH . "/Funcionario/bootstrap.php";
        },
        middlewares: [
            [AuthMiddleware::class, 'handle']
        ]
    );

    // ============================
    // Dispara o roteador
    // ============================
    $axiumPHP->routerDispatch();