package promptBuilder

import (
	"bytes"
	"fmt"
	"text/template"
)

func BuildPrompt(name string, in interface{}) (string, error) {
	fileLocation := "./prompts/" + name
	tmpl, err := template.New(name).ParseFiles(fileLocation)
	if err != nil {
		return "", fmt.Errorf("error parsing template: %w", err)
	}
	b := bytes.Buffer{}
	err = tmpl.Execute(&b, in)
	if err != nil {
		return "", fmt.Errorf("error executing template: %w", err)
	}
	return b.String(), nil
}
