<?php

use App\Models\Rental;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\RentalController;
use App\Http\Controllers\ProfileController;

// Redirect home to dashboard
Route::get('/', function () {
    return redirect('/dashboard');
});

// Authenticated Routes
Route::middleware(['auth', 'verified'])->group(function () {
    // Rental Dashboard
    Route::get('/dashboard', [RentalController::class, 'index'])->name('dashboard');
    Route::post('/sync', [RentalController::class, 'syncNow'])->name('rentals.sync');
    
    // User Profile
    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});

// API Route (returns JSON)
Route::get('/api/rentals', function() {
    return response()->json([
        'status' => 'success',
        'count' => Rental::count(),
        'data' => Rental::all()
    ]);
});

require __DIR__.'/auth.php';
