<?php

declare(strict_types=1);

namespace App\Middleware;

use App\Services\AuthService;

/**
 * Requires a valid Karvi Partner API Bearer token in session.
 */
final class AuthMiddleware
{
    public function __construct(
        private readonly AuthService $auth,
    ) {
    }

    public function requireAuth(): void
    {
        if ($this->auth->isAuthenticated()) {
            return;
        }

        redirect('/admin/login/');
    }

    public function requireGuest(): void
    {
        if ($this->auth->isAuthenticated()) {
            redirect('/admin/dashboard/');
        }
    }
}
