package prompt

import (
	"fmt"
	"strings"

	"github.com/tmc/langchaingo/llms"
)


var prompt_docstring = replaceWithBacktick(
`
file: {%s}
"""
{%s}
"""
`)

var prompt_docstring_zh = replaceWithBacktick(
`
文件: {%s}
"""
{%s}
"""

输出内容使用中文，我的母语为中文。
`)

var memory = []llms.MessageContent{
	llms.TextParts(llms.ChatMessageTypeHuman, replaceWithBacktick(
`
Your task is:
Write a documentation comment to the selected code. Please pay attention to using standard comment format, such as method comments, please explain parameters and return values. And just add the documents for the selected portion of the code.
Output documentation comment is format as code block.
You must follow the following rules:
1. Output documentation comment in """comment <documentation comments without code lines> """ format.
2. Different languages have different comment symbols, please choose the correct comment symbol according to the file name.
3. You must output ... to indicate the remaining code, output all code block can make more errors.
`)),

	llms.TextParts(llms.ChatMessageTypeGeneric, replaceWithBacktick(
`
file: a1.py
"""
    def print_hello():
        print("hello")
        print("world")
"""
`)),

	llms.TextParts(llms.ChatMessageTypeAI,
`comment
def print_hello():
	"""
	print hello

	Parameters:
	None

	Returns:
	None
	"""
	print("hello")
	...
`),

	llms.TextParts(llms.ChatMessageTypeHuman, replaceWithBacktick(
`
file: t1.java
"""
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
"""
`)),

	llms.TextParts(llms.ChatMessageTypeAI, 
`
comment
    /**
     * The main method is the entry point of the program.
     * This method prints "Hello, World!" to the console.
     *
     * @param args command line arguments (not used in this program)
     */
    public static void main(String[] args) {
        ...
`),

	llms.TextParts(llms.ChatMessageTypeHuman, replaceWithBacktick(
`
file: t1.py
"""
def content_to_json(content):
    try:
        content_no_block = _try_remove_markdown_block_flag(content)
        response_obj = json.loads(content_no_block)
        return response_obj
    except json.JSONDecodeError as err:
        raise RetryException(err) from err
    except Exception as err:
        raise err
"""
`)),

	llms.TextParts(llms.ChatMessageTypeAI, 
`comment
def content_to_json(content):
    """
    Convert the given content to a JSON object.

    Parameters:
    content (str): The content to convert.

    Returns:
    dict: The JSON object.

    Raises:
    RetryException: If the content cannot be decoded to JSON.
    """
    try:
        ...
`),
}

func replaceWithBacktick(s string) string {
    return strings.Replace(s, `"""`, "```", -1)
}

func MakeExecDocstring(lang, filePath, code string) []llms.MessageContent {
	contents := make([]llms.MessageContent, len(memory)+1)
	var formatter string
	if lang == "zh" {
		formatter = prompt_docstring_zh
	} else {
		formatter = prompt_docstring
	}
	copy(contents, memory)
	contents[len(contents)-1] = llms.TextParts(llms.ChatMessageTypeHuman, fmt.Sprintf(formatter, filePath, code))
	return contents
}



