<?php

namespace Modules\BI;

use Gestoreasy\Core\Module\ModuleInterface;
use Gestoreasy\Core\Routing\Router;
use Gestoreasy\Core\Http\AuthMiddleware;
use Gestoreasy\Core\Auth\Rbac;
use Modules\BI\Controllers\BIController;
use Modules\BI\Controllers\BIViewsController;

class Module implements ModuleInterface {
    public function register(Router $router): void {
        $biCtrl = new BIController();
        $biViewsCtrl = new BIViewsController();

        // Views
        $router->get('/bi', [$biViewsCtrl, 'dashboard'], [AuthMiddleware::requireAuthHtml(), Rbac::requirePermissions(['bi.dashboard'])]);
        $router->get('/bi/relatorios', [$biViewsCtrl, 'relatorios'], [AuthMiddleware::requireAuthHtml(), Rbac::requirePermissions(['bi.reports'])]);
        $router->get('/bi/config', [$biViewsCtrl, 'config'], [AuthMiddleware::requireAuthHtml(), Rbac::requirePermissions(['bi.config'])]);

        // API - Dashboard
        $router->get('/api/bi/dashboard/kpis', [$biCtrl, 'getKPIs'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['bi.dashboard'])]);
        $router->get('/api/bi/dashboard/vendas', [$biCtrl, 'getVendasChart'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['bi.dashboard'])]);
        $router->get('/api/bi/dashboard/estoque', [$biCtrl, 'getEstoqueChart'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['bi.dashboard'])]);
        $router->get('/api/bi/dashboard/financeiro', [$biCtrl, 'getFinanceiroChart'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['bi.dashboard'])]);

        // API - Relatórios Gerenciais
        $router->get('/api/bi/relatorios/dre', [$biCtrl, 'getDRE'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['bi.reports'])]);
        $router->get('/api/bi/relatorios/balanco', [$biCtrl, 'getBalanco'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['bi.reports'])]);
        $router->get('/api/bi/relatorios/fluxo-caixa', [$biCtrl, 'getFluxoCaixa'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['bi.reports'])]);

        // API - Exportação
        $router->get('/api/bi/relatorios/{tipo}/export', [$biCtrl, 'exportReport'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['bi.reports'])]);
    }
}

