<?php

use App\Http\Controllers\CommentController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\RegistrationController;
use App\Http\Controllers\ScoreboardController;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return auth()->check()
        ? redirect()->route('home')
        : redirect()->route('login');
})->name('landing');



Route::middleware('auth')->group(function () {
    
    Route::get('/dashboard', [HomeController::class, 'index'])->name('home');

    
    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');

    Route::get('/scoreboard', fn() => view('scoreboard'))->name('scoreboard');

    Route::group(['prefix' => 'registrations', 'as' => 'registrations.'], function () {
        Route::post('/send-otp', [RegistrationController::class, 'sendOtp'])->name('send-otp');
        Route::post('/verify-otp', [RegistrationController::class, 'verifyOtp'])->name('verify-otp');
        Route::get('/{id}/json', [RegistrationController::class, 'getRegistrationJson'])->name('get-json');
        Route::post('/record-shot', [RegistrationController::class, 'recordShot'])->name('record-shot');
        Route::post('/correct-shot', [RegistrationController::class, 'correctShot'])->name('correct-shot');
        Route::post('/record-shots', [RegistrationController::class, 'recordShots'])->name('record-shots');
        Route::get('/{id}/history', [RegistrationController::class, 'history'])->name('history');
        Route::post('/{id}/country', [RegistrationController::class, 'updateCountry'])->name('update-country');
        Route::post('/{id}/status', [RegistrationController::class, 'updateStatus'])->name('update-status');
    });

    Route::resource('comments', CommentController::class)->only(['index', 'store'])->names('comments');

    Route::get('/leaderboard', [RegistrationController::class, 'leaderboard'])->name('leaderboard');


    Route::post('scoreboard/select', [ScoreboardController::class, 'select'])->name('scoreboard.select');
    Route::get('scoreboard/state',   [ScoreboardController::class, 'state'])->name('scoreboard.state');
    Route::resource('registrations', RegistrationController::class)->names('registrations');



});

require __DIR__.'/auth.php';
