<?php

use App\Http\Controllers\DepartmentController;
use App\Http\Controllers\JDWizardController;
use App\Http\Controllers\LevelController;
use Illuminate\Support\Facades\Route;


Route::get('/jd/{token}', [JDWizardController::class, 'publicView'])->name('jd.public');

Route::middleware(['auth'])->group(function () {
    Route::get('/departments', [DepartmentController::class, 'index'])->name('departments.index');
    Route::get('/levels', [LevelController::class, 'index'])->name('levels.index');

    // JD Wizard
    Route::prefix('jd-wizard')->name('jd-wizard.')->group(function () {
        // JD Library dashboard
        Route::get('/', [JDWizardController::class, 'index'])->name('index');
 
        // Submit form (generate AI sections)
        Route::post('/create', [JDWizardController::class, 'create'])->name('create');
 
        // JD-scoped routes
        Route::prefix('/{jobDescription}')->group(function () {
 
            // Preview page (activity log)
            Route::get('/preview', [JDWizardController::class, 'preview'])->name('preview');
 
            // Manual section edit
            Route::put('/section', [JDWizardController::class, 'updateSection'])->name('section.update');
 
            // AI regenerate a section
            Route::post('/regenerate-section', [JDWizardController::class, 'regenerateSection'])->name('section.regenerate');
 
            // Add a custom section
            Route::post('/sections', [JDWizardController::class, 'addCustomSection'])->name('section.add');
 
            // Delete a custom section
            Route::delete('/sections/{section}', [JDWizardController::class, 'deleteCustomSection'])->name('section.delete');
 
            // Validation & alignment (runs all 14 checks, persists results)
            Route::get('/validation', [JDWizardController::class, 'validation'])->name('validation');
 
            // Save/revert to draft
            Route::post('/save-draft', [JDWizardController::class, 'saveDraft'])->name('save-draft');
 
            // Approve (with optional comment)
            Route::post('/approve', [JDWizardController::class, 'approve'])->name('approve');
 
            // Send back for revision
            Route::post('/send-back',  [JDWizardController::class, 'sendBack'])->name('send-back');
 
            // Publish (must be approved; generates public link)
            Route::post('/publish', [JDWizardController::class, 'publish'])->name('publish');
 
            // Export PDF / DOCX / link (published only)
            Route::post('/export', [JDWizardController::class, 'export'])->name('export');
        });
    });
});