<?php

declare(strict_types=1);

namespace App\Framework\ErrorHandling\Handlers;

use App\Framework\Http\Exception\HttpException;

/**
 * Handler for HTTP-specific errors
 *
 * Priority: NORMAL - Standard HTTP error handling
 */
final readonly class HttpErrorHandler implements ErrorHandlerInterface
{
    public function canHandle(\Throwable $exception): bool
    {
        return $exception instanceof HttpException;
    }

    public function handle(\Throwable $exception): HandlerResult
    {
        assert($exception instanceof HttpException);

        return HandlerResult::create(
            handled: true,
            message: $exception->getMessage(),
            data: [
                'error_type' => 'http',
                'headers' => $exception->headers ?? []
            ],
            statusCode: $exception->statusCode
        );
    }

    public function getName(): string
    {
        return 'http_error_handler';
    }

    public function getPriority(): ErrorHandlerPriority
    {
        return ErrorHandlerPriority::NORMAL;
    }
}
