<?php

use App\Http\Controllers\Web\AuthController;
use App\Http\Controllers\Web\ClientsController;
use App\Http\Controllers\Web\DashboardController;
use App\Http\Controllers\Web\DomainsController;
use App\Http\Controllers\Web\InvoicesController;
use App\Http\Controllers\Web\ProjectsController;
use App\Http\Controllers\Web\ReportsController;
use App\Http\Controllers\Web\ServersController;
use App\Http\Controllers\Web\TeamController;
use Illuminate\Support\Facades\Route;

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

Route::view('/welcome', 'welcome');

Route::middleware('guest')->group(function () {
    Route::get('/login', [AuthController::class, 'showLoginForm'])->name('login');
    Route::post('/login', [AuthController::class, 'login']);
});

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

    Route::name('web.')->group(function () {
        Route::get('/dashboard', DashboardController::class)->name('dashboard');
        Route::get('/clients', [ClientsController::class, 'index'])->name('clients.index');
        Route::get('/projects', [ProjectsController::class, 'index'])->name('projects.index');
        Route::get('/invoices', [InvoicesController::class, 'index'])->name('invoices.index');
        Route::get('/invoices/{invoice}/document', [InvoicesController::class, 'document'])->name('invoices.document');
        Route::get('/invoices/{invoice}/pdf', [InvoicesController::class, 'pdf'])->name('invoices.pdf');
        Route::get('/servers', [ServersController::class, 'index'])->name('servers.index');
        Route::get('/domains', [DomainsController::class, 'index'])->name('domains.index');
        Route::get('/team', [TeamController::class, 'index'])->name('team.index');
        Route::get('/reports', ReportsController::class)->name('reports.index');
    });
});
