<?php

use App\Http\Controllers\EmailConfigurationController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Email Configuration Routes
|--------------------------------------------------------------------------
|
| Routes for managing email configuration in the SSHIA Laravel System.
| All routes require authentication and Super Manager role.
|
| Route Naming Convention: config.email.{action}
| URL Prefix: /config/email
|
| IMPORTANT: All routes use controller-based routing.
| Closure-based routes are PROHIBITED to enable route caching.
|
*/

Route::middleware(['auth', 'role:Super Manager'])
    ->prefix('config/email')
    ->name('config.email.')
    ->group(function () {

        // Dashboard - Main index page showing configuration status
        Route::get('/', [EmailConfigurationController::class, 'index'])
            ->name('index');

        // Create - Show form to create new configuration
        Route::get('/create', [EmailConfigurationController::class, 'create'])
            ->name('create');

        // Store - Save new configuration (POST)
        Route::post('/', [EmailConfigurationController::class, 'store'])
            ->name('store');

        // Edit - Show form to edit existing configuration
        Route::get('/edit', [EmailConfigurationController::class, 'edit'])
            ->name('edit');

        // Update - Update existing configuration (PUT)
        Route::put('/', [EmailConfigurationController::class, 'update'])
            ->name('update');

        // Delete - Remove configuration (DELETE)
        Route::delete('/', [EmailConfigurationController::class, 'destroy'])
            ->name('destroy');

        // Test Connection - Test SMTP or IMAP connectivity (POST)
        Route::post('/test', [EmailConfigurationController::class, 'testConnection'])
            ->name('test');

        // Send Test Email - Send a test email for verification (POST)
        Route::post('/test-email', [EmailConfigurationController::class, 'sendTestEmail'])
            ->name('test-email');

        // Logs - View email operation logs
        Route::get('/logs', [EmailConfigurationController::class, 'logs'])
            ->name('logs');

        // Export Logs - Export logs as JSON
        Route::get('/logs/export', [EmailConfigurationController::class, 'exportLogs'])
            ->name('logs.export');

        // Documentation - Integration guide for developers
        Route::get('/documentation', [EmailConfigurationController::class, 'documentation'])
            ->name('documentation');

        // Get Status - AJAX endpoint for configuration status
        Route::get('/status', [EmailConfigurationController::class, 'getStatus'])
            ->name('status');

        // Clear Cache - Clear configuration cache
        Route::post('/clear-cache', [EmailConfigurationController::class, 'clearCache'])
            ->name('clear-cache');
    });
