<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
    /**
     * The application's global HTTP middleware stack.
     *
     * These middleware are run during every request to your application.
     *
     * @var array
     */
    protected $middleware = [
        \App\Http\Middleware\TrustHosts::class,
        \App\Http\Middleware\TrustProxies::class,
        \App\Http\Middleware\SecurityHeaders::class,
        \Fruitcake\Cors\HandleCors::class,
        \App\Http\Middleware\PreventRequestsDuringMaintenance::class,
        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
        \App\Http\Middleware\TrimStrings::class,
        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
    ];

    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            \App\Http\Middleware\NgbvdRateLimiter::class,
            \App\Http\Middleware\SessionIntegrityGuard::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \App\Http\Middleware\VerifySameOrigin::class,
            \App\Http\Middleware\SecurityInputGuard::class,
            \App\Http\Middleware\BusinessInputValidation::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
            \App\Http\Middleware\EnforceNgbvdRoutePermissions::class,
            \App\Http\Middleware\AuditSystemActivity::class,
        ],

        'api' => [
            'throttle:api',
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
            // Remove the line below to disable CSRF token validation
            // \App\Http\Middleware\VerifyCsrfToken::class,
        ],
    ];

    /**
     * The application's route middleware.
     *
     * These middleware may be assigned to groups or used individually.
     *
     * @var array
     */
    protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
        'can' => \Illuminate\Auth\Middleware\Authorize::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
        'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'ngbvd.permission' => \App\Http\Middleware\CheckNgbvdPermission::class,
        'ngbvd.api_client' => \App\Http\Middleware\CheckApiClient::class,
        'close.session.early' => \App\Http\Middleware\CloseSessionEarly::class,
        'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
        'security.rate' => \App\Http\Middleware\NgbvdRateLimiter::class,
        'security.business_validation' => \App\Http\Middleware\BusinessInputValidation::class,
        'security.session' => \App\Http\Middleware\SessionIntegrityGuard::class,
        'security.same_origin' => \App\Http\Middleware\VerifySameOrigin::class,
        'security.input' => \App\Http\Middleware\SecurityInputGuard::class,
            \App\Http\Middleware\BusinessInputValidation::class,
    ];

    /**
     * Force selected middleware order when route and group middleware are combined.
     *
     * CloseSessionEarly must run after authentication/permissions so the user is
     * known, but before heavy controller work so same-user tabs are not blocked.
     *
     * @var array
     */
    protected $middlewarePriority = [
        \Illuminate\Cookie\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \App\Http\Middleware\Authenticate::class,
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
        \App\Http\Middleware\EnforceNgbvdRoutePermissions::class,
        \App\Http\Middleware\CloseSessionEarly::class,
        \App\Http\Middleware\AuditSystemActivity::class,
    ];

}
