<?php

namespace App\Domains\Ai\Services;

class SlugSuggester
{
    public function __construct(private AiService $ai) {}

    /** @return string[] */
    public function suggest(string $targetUrl, int $count = 3): array
    {
        $prompt = "Generate exactly {$count} short memorable URL slugs (3-8 chars each, lowercase, letters/hyphens only, no numbers, comma-separated, no spaces) for this URL: {$targetUrl}. Reply with ONLY the comma-separated slugs, nothing else.";

        $raw = $this->ai->complete($prompt, 'claude-haiku-4-5-20251001');

        return collect(explode(',', $raw))
            ->map(fn ($s) => preg_replace('/[^a-z0-9-]/', '', strtolower(trim($s))))
            ->filter(fn ($s) => strlen($s) >= 2 && strlen($s) <= 16)
            ->take($count)
            ->values()
            ->all();
    }
}
