<?php

use App\Http\Controllers\AuthController;
use App\Http\Controllers\CvController;
use App\Http\Controllers\NotificationController;
use Illuminate\Support\Facades\Route;

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

// Authentication Routes (Guest)
Route::middleware('guest')->group(function () {
    Route::get('/login', [AuthController::class, 'showLogin'])->name('login');
    Route::post('/login', [AuthController::class, 'login']);
    Route::get('/register', [AuthController::class, 'showRegister'])->name('register');
    Route::post('/register', [AuthController::class, 'register']);
});

// Authentication Routes (Auth Required)
Route::middleware('auth')->group(function () {
    // OTP Verification
    Route::get('/verify', [AuthController::class, 'showVerify'])->name('auth.verify');
    Route::post('/verify', [AuthController::class, 'verify']);
    Route::post('/resend-otp', [AuthController::class, 'resendOtp'])->name('auth.resend');
    Route::post('/logout', [AuthController::class, 'logout'])->name('logout');

    // Verified routes (We'll enforce verification check in controller or dynamic middleware)
    Route::middleware('verified.whatsapp')->group(function () {
        Route::get('/dashboard', [CvController::class, 'index'])->name('dashboard');
        
        // CV CRUD
        Route::get('/cv/create', [CvController::class, 'create'])->name('cv.create');
        Route::post('/cv', [CvController::class, 'store'])->name('cv.store');
        Route::get('/cv/{cv}/edit', [CvController::class, 'edit'])->name('cv.edit');
        Route::put('/cv/{cv}', [CvController::class, 'update'])->name('cv.update');
        Route::delete('/cv/{cv}', [CvController::class, 'destroy'])->name('cv.destroy');
        Route::get('/cv/{cv}', [CvController::class, 'show'])->name('cv.show');

        // Realtime Alerts / Notifications
        Route::get('/api/notifications/poll', [NotificationController::class, 'poll'])->name('api.notifications.poll');
    });
});
