<?php

declare(strict_types=1);

namespace App\Config;

final class AgentRunnerConfig
{
    public function getShopPrompt(string $prompt, string $commerceHistoryContext = ''): string
    {
        $historyBlock = '';

        if (trim($commerceHistoryContext) !== '') {
            $historyBlock = '
            RECENT CONVERSATION CONTEXT:
            ' . $commerceHistoryContext . '
            
            Additional rules for conversation context:
            - The current user input has highest priority.
            - Use the recent conversation context only to resolve omitted references.
            - Use it only for product carry-over, brand carry-over, model carry-over, or variant follow-ups.
            - Do not revive older products unless the current user input clearly refers to them.
            - If the current input starts a new topic, ignore older product context.
            - Prefer the most recent product reference over older ones.
            ';
        }

        return '
            Generate a short search query for Shopware 6 from the following user input text.
            
            Rules:
            - Output only the final search query.
            - Always convert relevant search terms to their singular form.
            - No introduction, no explanation, no quotation marks.
            - Use only shop-relevant search terms from the user input for a shop search.
            - Maximum 6 search terms, preferably fewer.
            - Remove filler words, polite phrases, and irrelevant words.
            - Preserve product names, brands, model numbers, and compound terms exactly if they are relevant.
            - Numbers that belong to a product name or model must be preserved (e.g. Indikator 300, Testomat 808, Testomat 2000).
            - Separate terms using spaces only.
            - If a relevant product name is present, it must be placed at the beginning of the final search query.
            - Try to always identify all products mentioned in the user input text, even in long prompts.
            - Look for terms such as Testomat, Horiba, Tritromat, or words like indicator.
            - If the current user input is vague or referential, use the recent conversation context only as support.
            - Do not output words that only describe conversation flow, such as "same", "again", "also", or "like above".
            
            Output format:
            Keyword1 Keyword2 Keyword3
            ' . $historyBlock . '
            
            CURRENT USER INPUT:
            ' . $prompt . '
            ';
    }
}