<?php

namespace FleekDash\Routes\Groups;

use FleekDash\Libs\API\Route;
use FleekDash\Libs\API\RouteAuthMiddleware;
use FleekDash\Controllers\AuthController;

/**
 * System Routes
 *
 * API routes for system-level operations:
 * - Authentication (nonce, session, debug)
 * - Protected routes
 *
 * @package FleekDash\Routes\Groups
 * @since 2.2.0
 */
class SystemRoutes
{
    /**
     * Register all system-related routes
     *
     * @param Route $route Route instance
     * @return void
     */
    public static function register(Route $route)
    {
        // Authentication routes
        $route->post('/login', [AuthController::class, 'login'], RouteAuthMiddleware::public());
        $route->post('/register', [AuthController::class, 'register'], RouteAuthMiddleware::public());
        $route->post('/forgot-password', [AuthController::class, 'forgot_password'], RouteAuthMiddleware::public());
        $route->post('/auth/refresh-nonce', [AuthController::class, 'refresh_nonce'], RouteAuthMiddleware::public());
        $route->get('/auth/validate', [AuthController::class, 'validate'], RouteAuthMiddleware::public());
        $route->get('/auth/status', [AuthController::class, 'status'], RouteAuthMiddleware::public());
        $route->post('/logout', [AuthController::class, 'logout'], RouteAuthMiddleware::authenticated());
        $route->post('/auth/check-capability', [AuthController::class, 'check_capability'], RouteAuthMiddleware::authenticated(), [
            'capability' => [
                'required' => true,
                'type' => 'string',
                'description' => 'WordPress capability to check',
            ],
        ]);

        // Check multiple capabilities at once
        $route->post('/auth/check-capabilities', [AuthController::class, 'check_multiple_capabilities'], RouteAuthMiddleware::authenticated(), [
            'capabilities' => [
                'required' => true,
                'type' => 'array',
                'description' => 'Array of capabilities to check',
                'items' => [
                    'type' => 'string'
                ]
            ],
        ]);

        // Get current user capabilities summary
        $route->get('/auth/user-capabilities', [AuthController::class, 'get_user_capabilities'], RouteAuthMiddleware::authenticated());

        // Protected routes (admin only)
        $route->get('/protected', function () {
            return \rest_ensure_response(['message' => 'Protected route accessed successfully']);
        }, RouteAuthMiddleware::capability('manage_options'));

        // Gmail routes migrated to GmailRoutes (Phase 5.6)
        // See: includes/Routes/Groups/GmailRoutes.php
    }
}
