<?php
/**
 * TraderAlign — Simple Router
 * 
 * Maps URL paths to PHP files. No external dependencies.
 */

class Router
{
    private array $routes = [];

    /**
     * Register a route
     */
    public function add(string $method, string $path, string $file): void
    {
        $this->routes[] = compact('method', 'path', 'file');
    }

    /**
     * Dispatch the current request
     */
    public function dispatch(string $method, string $uri): void
    {
        // Strip query string and base path
        $uri = parse_url($uri, PHP_URL_PATH);
        $uri = str_replace('/traderalign', '', $uri);
        $uri = rtrim($uri, '/') ?: '/';

        foreach ($this->routes as $route) {
            if ($route['method'] === $method && $route['path'] === $uri) {
                require $route['file'];
                return;
            }
        }

        // 404
        http_response_code(404);
        echo '<h1>404 — Page Not Found</h1>';
    }
}