<?php

namespace Modules\Integracoes\OpenBanking;

use Gestoreasy\Core\Module\ModuleInterface;
use Gestoreasy\Core\Routing\Router;
use Gestoreasy\Core\Http\AuthMiddleware;
use Gestoreasy\Core\Auth\Rbac;
use Modules\Integracoes\OpenBanking\Controllers\OpenBankingController;

class Module implements ModuleInterface {
    public function register(Router $router): void {
        $ctrl = new OpenBankingController();

        // Views
        $router->get('/integracoes/open-banking', [$ctrl, 'dashboard'], [AuthMiddleware::requireAuthHtml(), Rbac::requirePermissions(['integracoes.openbanking.read'])]);

        // OAuth
        $router->get('/integracoes/open-banking/callback', [$ctrl, 'oauthCallback'], [AuthMiddleware::requireAuth()]);

        // API - Configuração
        $router->get('/api/openbanking/config', [$ctrl, 'getConfig'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['integracoes.openbanking.read'])]);
        $router->post('/api/openbanking/config', [$ctrl, 'updateConfig'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['integracoes.openbanking.update'])]);

        // API - Contas
        $router->get('/api/openbanking/contas', [$ctrl, 'listContas'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['integracoes.openbanking.read'])]);
        $router->get('/api/openbanking/contas/{id}/saldo', [$ctrl, 'getSaldo'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['integracoes.openbanking.read'])]);
        $router->get('/api/openbanking/contas/{id}/extrato', [$ctrl, 'getExtrato'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['integracoes.openbanking.read'])]);

        // API - Conciliação
        $router->post('/api/openbanking/conciliacao/automatica', [$ctrl, 'conciliacaoAutomatica'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['integracoes.openbanking.update'])]);
    }
}

