<?php

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

use Illuminate\Support\Facades\Route;
use Modules\Event\Entities\Event;
use Modules\Event\Entities\EventPhoto;
use Symfony\Component\HttpFoundation\Response;

Route::get('/', function () {
    return to_route('home');
})->name('index');

Route::get('event/{event}/pdf', function (Event $event) {
    abort_unless($event->is_active && $event->file_path && disk_public()->exists($event->file_path), Response::HTTP_NOT_FOUND);
    return disk_public()->download($event->file_path, $event->file_name);
})->name('front.event.download.pdf');

Route::get('event/{photo}/download/', function (EventPhoto $photo) {
    abort_unless($photo->is_active && $photo->path && disk_public()->exists($photo->path), Response::HTTP_NOT_FOUND);
    return disk_public()->download($photo->path, $photo->name);
})->name('front.event.download.photo');
