<?php
/**
 * Utility Routes
 *
 * API routes for cache, roles, and utility endpoints.
 * Migrated from: CacheAPI.php, RoleManagementAPI.php
 *
 * @package FleekDash V2.2
 * @since   V2.2 Refactoring - Phase 4
 */

namespace FleekDash\Routes\Groups;

use FleekDash\Libs\API\Route;
use FleekDash\Libs\API\RouteAuthMiddleware;
use FleekDash\Controllers\CacheController;
use FleekDash\Controllers\RolesController;
use FleekDash\Controllers\ErrorReportController;

class UtilityRoutes
{
    public static function register()
    {
        // ============================================
        // CACHE MANAGEMENT (4 routes)
        // ============================================

        // Check cache invalidation
        Route::get('cache/check-invalidation', [CacheController::class, 'checkInvalidation'],
            RouteAuthMiddleware::authenticated());

        // Clear invalidation flag
        Route::post('cache/clear-invalidation-flag', [CacheController::class, 'clearInvalidationFlag'],
            RouteAuthMiddleware::admin());

        // Clear transients
        Route::post('cache/clear-transients', [CacheController::class, 'clearAllTransients'],
            RouteAuthMiddleware::admin());

        // Set invalidation flag
        Route::post('cache/set-invalidation-flag', [CacheController::class, 'setInvalidationFlag'],
            RouteAuthMiddleware::admin());

        // ============================================
        // ROLE MANAGEMENT (5 routes)
        // ============================================

        // Get roles
        Route::get('roles', [RolesController::class, 'getRoles'],
            RouteAuthMiddleware::authenticated());

        // Create role
        Route::post('roles', [RolesController::class, 'createRole'],
            RouteAuthMiddleware::admin());

        // Update role
        Route::put('roles/{role_id}', [RolesController::class, 'updateRole'],
            RouteAuthMiddleware::admin(), [
            'role_id' => ['required' => true, 'type' => 'string', 'pattern' => '[a-zA-Z0-9-_]+']
        ]);

        // Delete role
        Route::delete('roles/{role_id}', [RolesController::class, 'deleteRole'],
            RouteAuthMiddleware::admin(), [
            'role_id' => ['required' => true, 'type' => 'string', 'pattern' => '[a-zA-Z0-9-_]+']
        ]);

        // Get capabilities
        Route::get('roles/capabilities', [RolesController::class, 'getCapabilities'],
            RouteAuthMiddleware::admin());

        // ============================================
        // ERROR REPORTING (1 route)
        // ============================================

        // Send error report
        Route::post('error-report', [ErrorReportController::class, 'sendReport'],
            RouteAuthMiddleware::public());
    }
}
