<?php

declare(strict_types=1);

namespace App\Framework\ErrorHandling\Handlers;

/**
 * Value Object representing a registered error handler with its priority.
 *
 * Replaces primitive array{handler: ErrorHandlerInterface, priority: int} pattern
 * with type-safe, immutable Value Object following framework principles.
 */
final readonly class HandlerRegistration
{
    public function __construct(
        public ErrorHandlerInterface $handler,
        public ErrorHandlerPriority $priority
    ) {}

    /**
     * Check if this handler can handle the given exception.
     */
    public function canHandle(\Throwable $exception): bool
    {
        return $this->handler->canHandle($exception);
    }

    /**
     * Execute the handler with the given exception.
     */
    public function handle(\Throwable $exception): HandlerResult
    {
        return $this->handler->handle($exception);
    }

    /**
     * Get handler name for debugging/logging.
     */
    public function getHandlerName(): string
    {
        return $this->handler->getName();
    }

    /**
     * Compare priority with another registration for sorting.
     */
    public function comparePriority(self $other): int
    {
        // Higher priority value = execute first (descending sort)
        return $other->priority->value <=> $this->priority->value;
    }
}
