<?php

namespace App\Services\AI;

class PromptBuilder
{
    public function build(string $message, array $context, array $memory): string
    {
        $prompt = "Context:\n";
        foreach ($context as $key => $value) {
            $prompt .= "- $key: " . (is_array($value) ? json_encode($value) : $value) . "\n";
        }

        if (!empty($memory)) {
            $prompt .= "\nRecent conversation:\n";
            foreach ($memory as $mem) {
                $prompt .= "User: {$mem['user']}\nAssistant: {$mem['assistant']}\n";
            }
        }

        $prompt .= "\nUser: $message\nAssistant:";

        return $prompt;
    }
}
