<?php

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

// Public route - accessible without authentication
Route::get('/job-descriptions/{jobId}/{slug}', [JobDescriptionController::class, 'publicView'])->name('jd.public.web');

Route::middleware('auth')
    ->prefix('dashboard/job-descriptions')
    ->name('dashboard.job-descriptions.')
    ->group(function () {

        Route::get('/', [JobDescriptionController::class, 'index'])->name('index');
        Route::get('/templates', [JobDescriptionController::class, 'templates'])->name('templates');
        Route::get('/create', [JobDescriptionController::class, 'create'])->name('create');
        Route::post('/', [JobDescriptionController::class, 'store'])->name('store');
        Route::get('/{jobDescription}/detail', [JobDescriptionController::class, 'detail'])->name('detail');
        Route::get('/{jobDescription}', [JobDescriptionController::class, 'show'])->name('show');
        Route::get('/{jobDescription}/edit', [JobDescriptionController::class, 'edit'])->name('edit');
        Route::put('/{jobDescription}', [JobDescriptionController::class, 'update'])->name('update');
        Route::delete('/{jobDescription}', [JobDescriptionController::class, 'destroy'])->name('destroy');

        // Wizard step routes
        Route::get('/{jobDescription}/generating', [JobDescriptionController::class, 'generating'])->name('generating');
        Route::get('/{jobDescription}/validate', [JobDescriptionController::class, 'validateStep'])->name('validate');
        Route::get('/{jobDescription}/review', [JobDescriptionController::class, 'review'])->name('review');
        Route::get('/{jobDescription}/publish', [JobDescriptionController::class, 'publish'])->name('publish');

        // Actions
        Route::post('/{jobDescription}/submit-approval', [JobDescriptionController::class, 'submitApproval'])->name('submit-approval');
        Route::post('/{jobDescription}/save-draft', [JobDescriptionController::class, 'saveDraft'])->name('save-draft');
        Route::post('/{jobDescription}/do-publish', [JobDescriptionController::class, 'doPublish'])->name('do-publish');
        Route::post('/{jobDescription}/unpublish', [JobDescriptionController::class, 'unpublish'])->name('unpublish');
        Route::post('/{jobDescription}/regenerate-section', [JobDescriptionController::class, 'regenerateSection'])->name('regenerate-section');
        Route::post('/{jobDescription}/export/{format}', [JobDescriptionController::class, 'export'])->name('export');

        // Custom sections
        Route::post('/{jobDescription}/sections', [JobDescriptionController::class, 'addCustomSection'])->name('section.add');
        Route::get('/{jobDescription}/viewPdf', [JobDescriptionController::class, 'viewPdf'])->name('view.pdf');
        Route::delete('/{jobDescription}/sections/{section}', [JobDescriptionController::class, 'deleteCustomSection'])->name('section.delete');
    });
