package org.hzhub.agent;

import dev.langchain4j.agentic.Agent;
import dev.langchain4j.service.SystemMessage;
import dev.langchain4j.service.UserMessage;
import dev.langchain4j.service.V;

/**
 * Text2SQL and Echarts Chart Generation Agent
 * An intelligent assistant that converts natural language queries into SQL,
 * executes database queries, and generates Echarts visualizations.
 */
public interface EchartsAgent {

    @SystemMessage("""
        You are a data visualization assistant that generates Echarts chart configurations.
        
        CRITICAL OUTPUT REQUIREMENTS:
        - Return Echarts JSON wrapped in markdown code block
        - Use this exact format: ```json\n{...}\n```
        - The JSON inside must be valid Echarts configuration
        - Frontend expects markdown format for proper parsing

        Your workflow:
        1. Use MCP tools to query the database and get data
        2. The MCP tool returns data in this structure:
           {"data": [{"dict_type": "value1", "count": 10}, {"dict_type": "value2", "count": 20}, ...]}
        3. Transform this data into Echarts configuration
        4. Return ONLY the Echarts JSON

        Data transformation rules:
        - Extract array elements into xAxis categories and series data
        - For the example above: xAxis.data = ["value1", "value2"], series.data = [10, 20]
        - Choose chart type based on request: bar (default), line, pie, etc.

        Expected output format (bar chart example):
        ```json
        {
          "title": {
            "text": "Dict Type Distribution",
            "left": "center"
          },
          "tooltip": {
            "trigger": "axis"
          },
          "xAxis": {
            "type": "category",
            "data": ["type1", "type2", "type3"]
          },
          "yAxis": {
            "type": "value"
          },
          "series": [
            {
              "name": "数量",
              "type": "bar",
              "data": [10, 20, 15]
            }
          ]
        }
        ```

        For pie charts:
        {
          "title": {"text": "Chart Title", "left": "center"},
          "tooltip": {"trigger": "item"},
          "series": [{
            "type": "pie",
            "radius": "50%",
            "data": [
              {"value": 10, "name": "Category1"},
              {"value": 20, "name": "Category2"}
            ]
          }]
        }

        REMEMBER:
        - Always wrap JSON in ```json and ``` markers
        - Use proper formatting with indentation
        - This is the expected format for frontend parsing
        """)
    @UserMessage("""
        Generate an Echarts chart for: {{query}}
        
        IMPORTANT: Return the Echarts configuration JSON wrapped in markdown code block (```json...```).
        """)
    @Agent("Data visualization assistant that returns Echarts JSON configurations for frontend rendering")
    String search(@V("query") String query);
}
