<?php

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        api: __DIR__.'/../routes/api.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware): void {
        $middleware->alias([
            'admin'         => \App\Http\Middleware\AdminMiddleware::class,
            'admin.access'  => \App\Http\Middleware\AdminAccessMiddleware::class,
            'import.api'    => \App\Http\Middleware\ImportApiMiddleware::class,
            'secure.player' => \App\Http\Middleware\SecurePlayer::class,
        ]);
        // Giriş yapılmamış kullanıcıyı frontend login sayfasına yönlendir
        $middleware->redirectGuestsTo(fn () => route('frontend.login'));
        // Bot koruması tüm web isteklerine uygula
        $middleware->web(\App\Http\Middleware\BotDetector::class);
        // SEO yönlendirmeleri
        $middleware->web(\App\Http\Middleware\SeoRedirectMiddleware::class);
        // iyzico callback CSRF muaf
        $middleware->validateCsrfTokens(except: ['checkout/callback']);
    })
    ->withExceptions(function (Exceptions $exceptions): void {
        //
    })->create();
