<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Symfony\Component\HttpFoundation\Response;

class SNCheckServerMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next
     */
    public function handle(Request $request, Closure $next): Response
    {
        $token = $request->header('sn-server-token');
        if ($token && $token === env('SN_SERVER_TOKEN')) {
            return $next($request);
        } else {
            return response()->json([
                'status' => false,
                'message' => '403 Forbidden'
            ], 403);
        }
    }
}
