<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Public\HomeController;
use App\Http\Controllers\Public\ContactController;
use App\Http\Controllers\Auth\AuthController;

Route::get('/', [HomeController::class, 'index'])->name('home');
Route::get('/orcamento', [HomeController::class, 'quote'])->name('quote.create');
Route::post('/orcamento', [HomeController::class, 'storeQuote'])->name('quote.store');
Route::get('/orcamento/{quote}/download', [HomeController::class, 'downloadQuote'])->name('quote.download');

// Public static pages
Route::get('/servicos', fn() => view('public.servicos'))->name('servicos');
Route::get('/projetos', fn() => view('public.projetos'))->name('projetos');
Route::get('/sobre', fn() => view('public.sobre'))->name('sobre');
Route::get('/contactos', [ContactController::class, 'index'])->name('contactos');
Route::post('/contactos', [ContactController::class, 'send'])->name('contact.send');

Route::middleware('guest')->group(function () {
    Route::get('login', [AuthController::class, 'create'])->name('login');
    Route::post('login', [AuthController::class, 'store'])->name('login.post');
    Route::get('forgot-password', [AuthController::class, 'forgotPassword'])->name('password.request');
    Route::post('forgot-password', [AuthController::class, 'sendResetLinkEmail'])->name('password.email');
});

Route::middleware('auth')->group(function () {
    Route::post('logout', [AuthController::class, 'destroy'])->name('logout');

    // Admin Panel Routes
    Route::prefix('admin')->name('admin.')->group(function () {
        Route::get('dashboard', [App\Http\Controllers\Admin\DashboardController::class, 'index'])->name('dashboard');
        
        Route::resource('clients', App\Http\Controllers\Admin\ClientController::class);
        Route::resource('installations', App\Http\Controllers\Admin\InstallationController::class);
        Route::resource('contracts', App\Http\Controllers\Admin\ContractController::class);
        Route::resource('tickets', App\Http\Controllers\Admin\TicketController::class);
        Route::resource('invoices', App\Http\Controllers\Admin\InvoiceController::class);

        Route::get('equipment', [App\Http\Controllers\Admin\EquipmentController::class, 'index'])->name('equipment.index');
        Route::get('equipment/create', [App\Http\Controllers\Admin\EquipmentController::class, 'create'])->name('equipment.create');
        Route::post('equipment', [App\Http\Controllers\Admin\EquipmentController::class, 'store'])->name('equipment.store');
    });

    // Client Area Routes
    Route::prefix('clientarea')->name('client.')->group(function () {
        Route::get('/', [App\Http\Controllers\Client\DashboardController::class, 'index'])->name('dashboard');
        Route::get('equipment', [App\Http\Controllers\Client\EquipmentController::class, 'index'])->name('equipment.index');
        Route::get('billing', [App\Http\Controllers\Client\BillingController::class, 'index'])->name('billing.index');
        Route::resource('tickets', App\Http\Controllers\Client\TicketController::class)->only(['index', 'create', 'store', 'show']);
    });
});
