<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\BookController;
use App\Http\Controllers\IssueController;

/*
|--------------------------------------------------------------------------
| 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!
|
*/

Route::get('/', function () {
    return view('welcome');
});

// Authentication Routes
Auth::routes(['verify' => true]);

// Home route - will redirect to welcome page after login


// Protected routes (require authentication)
Route::middleware(['auth'])->group(function () {
    // Book routes
    Route::get('/', function () {
    return view('welcome');
});
    Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
    Route::resource('books', BookController::class)->only(['index', 'create', 'store', 'show', 'edit', 'update', 'destroy']);
    Route::get('/books/{book}/copies', [BookController::class, 'copies'])->name('books.copies');
    Route::post('/books/{book}/copies', [BookController::class, 'storeCopy'])->name('books.copies.store');
    Route::put('/books/{book}/copies/{copy}', [BookController::class, 'updateCopy'])->name('books.copies.update');
    Route::delete('/books/{book}/copies/{copy}', [BookController::class, 'destroyCopy'])->name('books.copies.destroy');
    Route::delete('/copies/{copy}', [BookController::class, 'destroyCopy'])->name('copies.destroy');

    // Book Issuance Routes
    Route::get('/issues', [IssueController::class, 'index'])->name('issues.index');
    Route::get('/issues/create', [IssueController::class, 'create'])->name('issues.create');
    Route::post('/issues', [IssueController::class, 'store'])->name('issues.store');
    Route::post('/issues/{issue}/return', [IssueController::class, 'return'])->name('issues.return');

Route::get('/issues/student-history', [IssueController::class, 'studentHistory'])->name('issues.studentHistory');
});
