<?php

declare(strict_types=1);

namespace App\Framework\Router\Exception;

use App\Framework\Exception\ExceptionContext;
use App\Framework\Exception\FrameworkException;
use App\Framework\Http\Exception\HttpException;
use App\Framework\Http\Status;
use Throwable;

class RouteNotFound extends FrameworkException implements HttpException
{
    public Status $status {
        get {
            return Status::NOT_FOUND;
        }
    }

    protected string $route;

    /**
     * @param array<string, mixed> $context
     */
    public function __construct(string $route, ?Throwable $previous = null, int $code = 0, array $context = [])
    {
        $this->route = $route;
        $message = "Route not found: {$route}";

        $exceptionContext = new ExceptionContext(
            operation: 'route_resolution',
            component: 'router',
            data: array_merge(['route' => $route], $context)
        );

        parent::__construct($message, $exceptionContext, $code, $previous);
    }
}
