<?php
// File: app/Middleware/GuestMiddleware.php

namespace Core\Middleware;

use Core\Auth;
use Core\Response;

class GuestMiddleware implements MiddlewareInterface
{
    public function handle(string $uri, string $method, array $params): bool
    {
        if (Auth::check()) {

            $user = Auth::user();
            switch ($user['role']) {
                case 'admin':
                    Response::redirect('/admin');
                    return false;
                case 'responder':
                    Response::redirect('/responder');
                    return false;
                default:
                    // If user is already logged in, redirect to dashboard
                    Response::redirect('/dashboard');
                    return false;
            }
        }
        return true;
    }
}