<?php

namespace App\Services\AI;

use App\Contracts\StyleSuggester;
use App\DTOs\CreativeBrief;
use Illuminate\Contracts\JsonSchema\JsonSchema;

use function Laravel\Ai\agent;

class LaravelAiStyleSuggester implements StyleSuggester
{
    public function suggest(CreativeBrief $brief): string
    {
        $prompt = sprintf(
            "Product: %s\nFeatures: %s\nBenefits: %s\nMessaging: %s",
            $brief->productName,
            implode(', ', $brief->features),
            implode(', ', $brief->benefits),
            $brief->messaging,
        );

        $response = agent(
            instructions: 'You suggest a short visual style for an ad creative, e.g. "minimalist, high-contrast, bold typography". Reply with a single comma-separated phrase, not a full sentence.',
            schema: fn (JsonSchema $schema) => [
                'style' => $schema->string()->required(),
            ],
        )->prompt($prompt);

        return $response->toArray()['style'];
    }
}
