<?php

use App\Http\Controllers\CareerController;
use App\Http\Controllers\Admin\CareerController as AdminCareerController;
use App\Http\Controllers\Admin\JobApplicationController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Public Routes
|--------------------------------------------------------------------------
*/

// Redirect root to login (admin panel)
Route::get('/', function () {
    return redirect()->route('login');
});

// Frontend Career Routes (public)
Route::get('/careers', [CareerController::class, 'index'])->name('careers.index');
Route::get('/careers/{slug}', [CareerController::class, 'show'])->name('careers.show');

/*
|--------------------------------------------------------------------------
| Admin Routes (Protected with Authentication)
|--------------------------------------------------------------------------
*/

Route::middleware(['auth', 'admin'])->prefix('admin')->name('admin.')->group(function () {
    
    // Admin Dashboard - Redirect to careers
    Route::get('/', function () {
        return redirect()->route('admin.careers.index');
    })->name('dashboard');
    
    // Career Routes
    Route::resource('careers', AdminCareerController::class);
    Route::patch('careers/{career}/toggle', [AdminCareerController::class, 'toggle'])->name('careers.toggle');
    
    // Application Routes
    Route::resource('applications', JobApplicationController::class)->only(['index', 'show', 'update', 'destroy']);
    Route::get('applications/{application}/resume', [JobApplicationController::class, 'downloadResume'])->name('applications.resume');

    // Profile Routes
    Route::get('/profile', function () {
        return view('admin.profile');
    })->name('profile.edit');
    Route::patch('/profile', [\App\Http\Controllers\ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [\App\Http\Controllers\ProfileController::class, 'destroy'])->name('profile.destroy');
});

require __DIR__.'/auth.php';