<?php

declare(strict_types=1);

namespace App\Framework\Console\ErrorRecovery;

use App\Framework\Console\ConsoleCommand;

final readonly class CommandSuggestion
{
    public function __construct(
        public ConsoleCommand $command,
        public float $similarity,
        public SuggestionReason $reason
    ) {
    }

    public function getFormattedSuggestion(): string
    {
        $percentage = round($this->similarity * 100);
        $reasonText = $this->reason->getDisplayText();

        return sprintf(
            '%s (%d%% match - %s)',
            $this->command->name,
            $percentage,
            $reasonText
        );
    }

    public function getDetailedSuggestion(): string
    {
        return sprintf(
            "Command: %s\nDescription: %s\nMatch: %.1f%% (%s)",
            $this->command->name,
            $this->command->description,
            $this->similarity * 100,
            $this->reason->getDisplayText()
        );
    }

    public function isHighConfidence(): bool
    {
        return $this->similarity >= 0.8;
    }

    public function isMediumConfidence(): bool
    {
        return $this->similarity >= 0.5 && $this->similarity < 0.8;
    }

    public function isLowConfidence(): bool
    {
        return $this->similarity < 0.5;
    }
}
