<?php

declare(strict_types=1);

namespace App\Application\LiveComponents\ValueObjects;

/**
 * Suggestion - Represents a single autocomplete suggestion
 */
final readonly class Suggestion
{
    public function __construct(
        public string $text,
        public string $category,
        public string $icon
    ) {
    }

    public function toArray(): array
    {
        return [
            'text' => $this->text,
            'category' => $this->category,
            'icon' => $this->icon,
        ];
    }

    public function matches(string $query): bool
    {
        return str_contains(strtolower($this->text), strtolower($query));
    }

    public function exactMatch(string $query): bool
    {
        return strtolower($this->text) === strtolower($query);
    }

    public function startsWith(string $query): bool
    {
        return str_starts_with(strtolower($this->text), strtolower($query));
    }
}
