<?php

use Illuminate\Support\Facades\Route;
use Laravel\Fortify\Features;

Route::inertia('/', 'Welcome', [
    'canRegister' => Features::enabled(Features::registration()),
])->name('home');

Route::middleware(['auth', 'verified'])->group(function () {
    Route::get('dashboard', \App\Http\Controllers\DashboardController::class)->name('dashboard');
    Route::post('workspace/switch', \App\Http\Controllers\WorkspaceSwitchController::class)
        ->name('workspace.switch');

    Route::middleware('workspace')->group(function () {
        Route::resource('clients', \App\Http\Controllers\ClientController::class);
        Route::resource('declarations', \App\Http\Controllers\DeclarationController::class);
        Route::post('declarations/{declaration}/messages', [\App\Http\Controllers\DeclarationMessageController::class, 'store'])
            ->name('declarations.messages.store');
        Route::post('declarations/{declaration}/media', [\App\Http\Controllers\DeclarationMediaController::class, 'store'])
            ->name('declarations.media.store');
        Route::get('declarations/{declaration}/media/{mediaId}', [\App\Http\Controllers\DeclarationMediaController::class, 'download'])
            ->name('declarations.media.download')
            ->whereNumber('mediaId');
        Route::post('declarations/{declaration}/mentions', [\App\Http\Controllers\DeclarationMentionController::class, 'store'])
            ->middleware('throttle:10,1')
            ->name('declarations.mentions.store');
        Route::post('declarations/{declaration}/nudge', [\App\Http\Controllers\NudgeController::class, 'store'])
            ->middleware('throttle:10,1')
            ->name('declarations.nudge');

        Route::get('team', [\App\Http\Controllers\TeamController::class, 'index'])->name('team.index');
        Route::post('team/invite', [\App\Http\Controllers\TeamController::class, 'invite'])->name('team.invite');
        Route::patch('team/{workspaceUserId}/role', [\App\Http\Controllers\TeamController::class, 'updateRole'])->name('team.updateRole');
        Route::put('team/{workspaceUserId}/permissions', [\App\Http\Controllers\TeamController::class, 'updatePermissions'])->name('team.updatePermissions');
        Route::delete('team/{workspaceUserId}', [\App\Http\Controllers\TeamController::class, 'remove'])->name('team.remove');

        Route::get('notifications', [\App\Http\Controllers\NotificationController::class, 'index'])->name('notifications.index');
        Route::post('notifications/mark-all-read', [\App\Http\Controllers\NotificationController::class, 'markAllAsRead'])->name('notifications.readAll');
        Route::post('notifications/{id}/read', [\App\Http\Controllers\NotificationController::class, 'markAsRead'])->name('notifications.read');
    });

    Route::middleware('admin')->group(function () {
        Route::resource('users', \App\Http\Controllers\UserController::class);
        Route::resource('workspaces', \App\Http\Controllers\WorkspaceController::class);
    });
});

Route::prefix('c')->name('client.')->middleware('client-portal')->group(function () {
    Route::get('upload/{token}', [\App\Http\Controllers\Client\UploadController::class, 'show'])
        ->name('upload');
    Route::post('upload/{token}', [\App\Http\Controllers\Client\UploadController::class, 'store'])
        ->name('upload.store');
    Route::get('confirm/{token}', [\App\Http\Controllers\Client\ConfirmController::class, 'show'])
        ->name('confirm');
    Route::post('confirm/{token}', [\App\Http\Controllers\Client\ConfirmController::class, 'store'])
        ->name('confirm.store');
    Route::get('refuse/{token}', [\App\Http\Controllers\Client\RefuseController::class, 'show'])
        ->name('refuse');
    Route::post('refuse/{token}', [\App\Http\Controllers\Client\RefuseController::class, 'store'])
        ->name('refuse.store');
});

require __DIR__.'/settings.php';
