<?php

namespace Modules\Integracoes\Instagram;

use Gestoreasy\Core\Module\ModuleInterface;
use Gestoreasy\Core\Routing\Router;
use Gestoreasy\Core\Http\AuthMiddleware;
use Gestoreasy\Core\Auth\Rbac;
use Modules\Integracoes\Instagram\Controllers\InstagramController;
use Modules\Integracoes\Instagram\Controllers\InstagramViewsController;

class Module implements ModuleInterface {
    public function register(Router $router): void {
        $apiCtrl = new InstagramController();
        $viewsCtrl = new InstagramViewsController();

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

        // OAuth Callback
        $router->get('/integracoes/instagram/callback', [$apiCtrl, 'oauthCallback'], [AuthMiddleware::requireAuth()]);

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

        // API - Produtos
        $router->get('/api/instagram/produtos', [$apiCtrl, 'listProdutos'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['integracoes.instagram.read'])]);
        $router->post('/api/instagram/produtos/sincronizar', [$apiCtrl, 'sincronizarProdutos'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['integracoes.instagram.update'])]);

        // API - Publicações
        $router->get('/api/instagram/publicacoes', [$apiCtrl, 'listPublicacoes'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['integracoes.instagram.read'])]);
        $router->post('/api/instagram/publicacoes', [$apiCtrl, 'criarPublicacao'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['integracoes.instagram.update'])]);

        // API - Estatísticas
        $router->get('/api/instagram/estatisticas', [$apiCtrl, 'getEstatisticas'], [AuthMiddleware::requireAuth(), Rbac::requirePermissions(['integracoes.instagram.read'])]);

        // Webhooks
        $router->post('/api/instagram/webhook', [$apiCtrl, 'webhook'], []);
    }

    public function name(): string { return 'Instagram'; }
    public function version(): string { return '1.0.0'; }
    public function dependencies(): array { return []; }
}

