<?php

use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\AchatController;
use App\Http\Controllers\CautionController;
use App\Http\Controllers\ClientController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\DepenseController;
use App\Http\Controllers\FournisseurControlleur;
use App\Http\Controllers\InvoiceController;
use App\Http\Controllers\MagasinController;
use App\Http\Controllers\MouvementController;
use App\Http\Controllers\ProduitController;
use App\Http\Controllers\StockController;
use App\Http\Controllers\TransferStockController;
use App\Http\Controllers\TransfertStockController;
use App\Http\Controllers\VenteController;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return auth()->check() ? redirect()->route('dashboard') : redirect()->route('login');
});

Route::get('/login', [LoginController::class, 'showLoginForm'])->name('login')->middleware('guest');
Route::post('/login', [LoginController::class, 'login'])->middleware('guest');
Route::post('/logout', [LoginController::class, 'logout'])->name('logout')->middleware('auth');

Route::middleware('auth')->group(function () {
    Route::get('/dashboard', DashboardController::class)->name('dashboard');
    Route::put('magasins/{id}/disabled', [MagasinController::class, 'disabledStore'])->name('magasins.disabled');
    Route::resource('magasins', MagasinController::class);
    Route::resource('clients', ClientController::class)->parameters(['clients' => 'id']);
    Route::resource('fournisseurs', FournisseurControlleur::class)->parameters(['fournisseurs' => 'id']);
    Route::get('depenses/export', [DepenseController::class, 'export'])->name('depenses.export');
    Route::resource('depenses', DepenseController::class)->parameters(['depenses' => 'id']);
    Route::get('produits/export', [ProduitController::class, 'export'])->name('produits.export');
    Route::resource('produits', ProduitController::class)->parameters(['produits' => 'id']);
    Route::get('transferts/export', [TransfertStockController::class, 'export'])->name('transferts.export');
    Route::resource('transferts', TransfertStockController::class)->parameters(['transferts' => 'id']);
    Route::post('ventes/store-client', [VenteController::class, 'storeClient'])->name('ventes.store-client');
    Route::resource('ventes', VenteController::class)->parameters(['ventes' => 'id']);
    Route::resource('achats', AchatController::class)->parameters(['achats' => 'id']);

    /*** Stock Module ***/
    Route::get('stock/export', [StockController::class, 'export'])->name('stock.export');
    Route::get('/stock', StockController::class)->name('stock.index');

    /*** Mouvements Module ***/
    Route::get('mouvements/export', [MouvementController::class, 'export'])->name('mouvements.export');
    Route::get('mouvements', [MouvementController::class, 'index'])->name('mouvements.index');
    Route::get('factures', [InvoiceController::class, 'index'])->name('factures.index');
    Route::get('factures/export', [InvoiceController::class, 'export'])->name('factures.export');
});

// Route::get('/ventes', function () {
//     return view('ventes.index');
// })->name('ventes.index');

Route::get('/cautions/export', [CautionController::class, 'export'])->name('cautions.export');
Route::get('/cautions', [CautionController::class, 'index'])->name('cautions.index');



// Route::get('/factures', function () {
//     return view('factures.index');
// })->name('factures.index');

// Route::get('/achats', function () {
//     return view('achats.index');
// })->name('achats.index');



// Route::get('/mouvements', function () {
//     return view('mouvements.index');
// })->name('mouvements.index');

Route::get('/personnel', function () {
    return view('personnel.index');
})->name('personnel.index');

Route::get('/inventaire', function () {
    return view('inventaire.index');
})->name('inventaire.index');

Route::get('/audits', function () {
    return view('audits.index');
})->name('audits.index');

Route::get('/rapports', function () {
    return view('rapports.index');
})->name('rapports.index');
