<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\EnrollUserController;
use App\Http\Controllers\UsersListController;
use App\Http\Controllers\ImageController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
    return view('home');
});


Route::post('/add-user', [EnrollUserController::class, 'enrollUserAction'])->middleware('auth')->name('enroll-user');

Route::get('/users-list', [UsersListController::class, 'listUsersAction'])->middleware('auth')->name('users-list');

Route::get('/faces', [UsersListController::class, 'listFacesAction'])->middleware('auth')->name('faces-list');
Route::get('/delete-pictures', [UsersListController::class, 'deletePictures'])->middleware('auth')->name('deletePictures');



Route::get('/add-user', function (Request $request) {
    return view('add-user');
})->middleware('auth')->name('add-user');


Route::get('/image', [ImageController::class, 'index']);


Route::get('/recordings', function () {
    $recordingsDirectory = storage_path('app/recordings');
    $recordings = File::allFiles($recordingsDirectory);

    return view('recordings', [
        'recordings' => $recordings
    ]);
})->middleware('auth')->name('recordings');

Route::get('/recordings/{filename}', function ($filename) {
    $recordingsDirectory = storage_path('app/recordings');
    $filePath = $recordingsDirectory . '/' . $filename;

    $headers = [
        'Content-Type' => 'video/mp4'
    ];

    return Response::file($filePath, $headers);
})->name('play-recording');



Auth::routes();

Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
