<?php

declare(strict_types=1);

namespace App\Application\Middleware;

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface as Handler;
use PDO;

class AdminAuthMiddleware implements MiddlewareInterface
{
    public function process(Request $request, Handler $handler): Response
    {
        if (empty($_SESSION['admin_user'])) {
            $response = new \Slim\Psr7\Response();
            return $response->withHeader('Location', '/admin/login')->withStatus(302);
        }
        return $handler->handle($request);
    }
}
