package llm

import (
	"encoding/json"
	"fmt"

	"github.com/nexuscrm/sentry/internal/types"
)

// systemPrompt is the hard-coded guardrail prompt for alert translation.
// It enforces:
//  1. Facts-only (no causal speculation)
//  2. Max 5 lines
//  3. No emoji beyond the caller-provided severity icon
//  4. Must include metric name, current value, baseline, delta
const systemPrompt = `You are an ops alert formatter for a CRM monitoring system.
Your job: restate a structured alert as a clear, concise message in English.
Rules:
1. State the FACTS ONLY. Do NOT speculate about causes.
2. Do NOT suggest actions beyond "human investigation recommended".
3. Use at most 5 lines. No emoji.
4. Include the metric name, current value, baseline value, and delta when available.
5. Never invent data not present in the input JSON.`

// buildUserPrompt returns the JSON-encoded rule result wrapped as a user message.
// Returns an error only if the result cannot be marshaled (should never happen in
// practice because RuleResult is plain data).
func buildUserPrompt(r types.RuleResult) (string, error) {
	b, err := json.Marshal(r)
	if err != nil {
		return "", fmt.Errorf("llm: marshal rule result: %w", err)
	}
	return string(b), nil
}
