<?php

namespace App\Http\Middleware;

use App\Departement;
use App\Key;
use Closure;

class VerifyApiKey
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        return $next($request);
        /*
        if ($request->bd && $request->departement) {
            $bd = hackKey(false, $request->bd);
            $departement = hackKey(false, $request->departement);


            // We check API key in database and with admin one 44b48f2305
                if (Key::all()->where('bd', '=', $bd)->where('departement_id', '=', $departement)->first()->statut == 'PUBLISHED') {
                    $dep = Key::all()->where('bd', '=', $bd)->where('departement_id', '=', $departement)->first();
                    $request['SchoolDep'] = $dep;
                    return $next($request);
                } else {
                    return response()->json([
                        'results' => 'DEPARTEMENT_NOT_ALLOWED'
                    ], 403);
                }
            /*} else {
                return response()->json([
                    'results' => 'API key is not valid',
                ]);
            }*
        }
        
        return response()->json([

            'results' => 'Authorization failed',
        ]);
        */
    }
}
