<?php
/**
 * Gmail Routes
 *
 * API routes for Gmail integration.
 * Migrated from Gmail.php, GmailEndpoints.php, and GmailSettings.php (legacy).
 *
 * @package FleekDash\Routes\Groups
 * @since 2.2.0
 */

namespace FleekDash\Routes\Groups;

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

class GmailRoutes
{
    /**
     * Register all Gmail-related routes
     *
     * @param Route $route Route instance
     * @return void
     */
    public static function register(Route $route)
    {
        // ============================================
        // GMAIL AUTHENTICATION ROUTES
        // ============================================

        // Initialize OAuth flow
        Route::post('gmail/auth', [GmailController::class, 'init_auth'],
            RouteAuthMiddleware::admin());

        // OAuth callback (public for Google redirect)
        Route::get('gmail/callback', [GmailController::class, 'handle_callback'],
            RouteAuthMiddleware::public());

        // ============================================
        // GMAIL MESSAGES ROUTES
        // ============================================

        // List Gmail messages
        Route::get('gmail/messages', [GmailController::class, 'list_messages'],
            RouteAuthMiddleware::admin());

        // Get specific Gmail message
        Route::get('gmail/messages/{id}', [GmailController::class, 'get_message'],
            RouteAuthMiddleware::admin(), [
            'id' => [
                'required' => true,
                'type' => 'string',
                'description' => 'Gmail message ID',
                'validate_callback' => function ($param) {
                    return !empty($param);
                }
            ]
        ]);

        // Disconnect Gmail account
        Route::post('gmail/disconnect', [GmailController::class, 'disconnect'],
            RouteAuthMiddleware::admin());

        // ============================================
        // GMAIL SETTINGS ROUTES
        // ============================================

        // Get Gmail settings
        Route::get('settings/gmail', [GmailController::class, 'get_settings'],
            RouteAuthMiddleware::admin());

        // Update Gmail settings
        Route::post('settings/gmail', [GmailController::class, 'update_settings'],
            RouteAuthMiddleware::admin(), [
            'fleekdash_gmail_client_id' => [
                'required' => true,
                'type' => 'string',
                'description' => 'Gmail OAuth Client ID'
            ],
            'fleekdash_gmail_client_secret' => [
                'required' => true,
                'type' => 'string',
                'description' => 'Gmail OAuth Client Secret'
            ]
        ]);
    }
}

