<?php

namespace EasyLinkAutomations\HTTP\Router;

if (!defined('ABSPATH')) {
    exit;
}

/**
 * Represents a single registered route.
 * Holds a reference back to the Router so that chaining ->middleware()
 * on a single route applies middleware only to that specific route.
 */
final class RouteEntry
{
    private Router $router;
    private int $index;

    public function __construct(Router $router, int $index)
    {
        $this->router = $router;
        $this->index  = $index;
    }

    /**
     * Attach middleware to this individual route (chainable).
     *
     * @return static
     */
    public function middleware(string ...$names): static
    {
        $this->router->applyMiddlewaresToIndex($this->index, array_values($names));

        return $this;
    }
}
