<?php

namespace App\Http;

use App\Http\Middleware\Affiliate;
use App\Http\Middleware\CheckForMaintenanceMode;
use App\Http\Middleware\EncryptCookies;
use App\Http\Middleware\isAdmin;
use App\Http\Middleware\isAdminlogin;
use App\Http\Middleware\isForbidden;
use App\Http\Middleware\isLogin;
use App\Http\Middleware\isMaintenance;
use App\Http\Middleware\isSecurity;
use App\Http\Middleware\RedirectIfAuthenticated;
use App\Http\Middleware\SetLocale;
use App\Http\Middleware\TrimStrings;
use App\Http\Middleware\TrustProxies;
use App\Http\Middleware\VerifyCsrfToken;
use App\Http\Middleware\WebApi;
use Illuminate\Auth\Middleware\Authenticate;
use Illuminate\Auth\Middleware\AuthenticateWithBasicAuth;
use Illuminate\Auth\Middleware\Authorize;
use Illuminate\Auth\Middleware\EnsureEmailIsVerified;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull;
use Illuminate\Foundation\Http\Middleware\ValidatePostSize;
use Illuminate\Http\Middleware\SetCacheHeaders;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Routing\Middleware\ValidateSignature;
use Illuminate\Session\Middleware\AuthenticateSession;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;

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 = [
		CheckForMaintenanceMode::class,
		ValidatePostSize::class,
		TrimStrings::class,
		ConvertEmptyStringsToNull::class,
		TrustProxies::class,
	];

	/**
	 * The application's route middleware groups.
	 *
	 * @var array
	 */
	protected $middlewareGroups = [
		'web' => [
			EncryptCookies::class,
			AddQueuedCookiesToResponse::class,
			StartSession::class,
			// \Illuminate\Session\Middleware\AuthenticateSession::class,
			SetLocale::class,
			ShareErrorsFromSession::class,
			VerifyCsrfToken::class,
			SubstituteBindings::class,
		],

		'api' => [
			'throttle:60,1',
			'bindings',
		],
	];

	/**
	 * The application's route middleware.
	 *
	 * These middleware may be assigned to groups or used individually.
	 *
	 * @var array
	 */
	protected $routeMiddleware = [
		'auth'          => Authenticate::class,
		'auth.basic'    => AuthenticateWithBasicAuth::class,
		'bindings'      => SubstituteBindings::class,
		'cache.headers' => SetCacheHeaders::class,
		'can'           => Authorize::class,
		'guest'         => RedirectIfAuthenticated::class,
		'signed'        => ValidateSignature::class,
		'throttle'      => ThrottleRequests::class,
		'verified'      => EnsureEmailIsVerified::class,
		'webApi'        => WebApi::class,
		'isAdmin'       => isAdmin::class,
		'isAdminLogin'  => isAdminLogin::class,
		'isLogin'       => isLogin::class,
		'isMaintenance' => isMaintenance::class,
		'isSecurity'    => isSecurity::class,
		'isForbidden'   => isForbidden::class,
		'affiliate'     => Affiliate::class,

	];


	/**
	 * The priority-sorted list of middleware.
	 *
	 * This forces non-global middleware to always be in the given order.
	 *
	 * @var array
	 */
	protected $middlewarePriority = [
		StartSession::class,
		ShareErrorsFromSession::class,
		Middleware\Authenticate::class,
		AuthenticateSession::class,
		SubstituteBindings::class,
		Authorize::class,
	];
}
