<?php

declare(strict_types=1);

namespace App\Framework\Router;

use App\Framework\Http\Method;
use Closure;

final class RouteContext
{
    public null|Closure $handler {
        get => $this->isSuccess() ? $this->match->route->method : null;
    }

    public array $params {
        get => $this->isSuccess() ? $this->match->route->parameters : [];
    }

    public function __construct(
        public readonly RouteMatch $match,
        public readonly Method     $method,
        public readonly string     $path
    ) {
    }

    public function isSuccess(): bool
    {
        return $this->match instanceof RouteMatchSuccess;
    }
}
