<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

use Wave\Facades\Wave;
use App\Http\Controllers\OrderController;
use App\Http\Controllers\PaymentController;
use App\Http\Controllers\DiscountController;

// Wave routes
Wave::routes();

// PDF download route
Route::middleware('auth')->get('/order/{id}/pdf', [OrderController::class, 'downloadPdf'])->name('order.pdf');
Route::middleware('auth')->get('/payment/{id}/pdf', [PaymentController::class, 'downloadPdf'])->name('payment.pdf');

// Discount routes
Route::middleware('auth')->post('/client/{clientId}/discount', [DiscountController::class, 'store'])->name('discount.store');

// Route initiale - redirection vers dashboard si connecté, sinon login
Route::get('/', function () {
    if (auth()->check()) {
        return redirect()->route('dashboard');
    } else {
        return redirect()->route('login');
    }
});