<?php

namespace Modules\Integracoes\WhatsApp;

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

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

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

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

        // API - Mensagens
        $router->post('/api/whatsapp/enviar', [$ctrl, 'enviarMensagem'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['integracoes.whatsapp.send'])]);
        $router->get('/api/whatsapp/mensagens', [$ctrl, 'listMensagens'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['integracoes.whatsapp.read'])]);
        $router->get('/api/whatsapp/templates', [$ctrl, 'listTemplates'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['integracoes.whatsapp.read'])]);

        // Webhook (público, validação interna)
        $router->post('/api/whatsapp/webhook', [$ctrl, 'webhook'], []);
    }
}

