package ownpost

import (
	"strings"
	"testing"
)

func TestBuildReplyDraftPromptIncludesPersonaPostAndReply(t *testing.T) {
	_, user := BuildReplyDraftPrompt(ReplyDraftInput{
		AccountName:  "小安",
		PersonaBlock: "溫柔媽媽，說話慢、會先共情",
		PostText:     "今天帶小孩好累",
		ReplyText:    "我也是欸",
		ReplyToID:    "123",
	})
	for _, want := range []string{"【1. 人設】", "溫柔媽媽", "【2. 我的貼文】", "今天帶小孩好累", "【3. 要回覆的留言】", "我也是欸"} {
		if !strings.Contains(user, want) {
			t.Fatalf("missing %q in user prompt:\n%s", want, user)
		}
	}
}

func TestBuildReplyDraftPromptThreadContinuation(t *testing.T) {
	_, user := BuildReplyDraftPrompt(ReplyDraftInput{
		PersonaBlock: "生活觀察者",
		PostText:     "最近在想轉職",
	})
	if !strings.Contains(user, "接續自己貼文") {
		t.Fatalf("expected thread continuation hint, got:\n%s", user)
	}
	if strings.Contains(user, "【3. 要回覆的留言】\n（無特定留言") {
		// ok
	} else if !strings.Contains(user, "無特定留言") {
		t.Fatalf("expected empty reply section marker, got:\n%s", user)
	}
}

func TestBuildMentionReplyDraftPromptIncludesThreadAndMention(t *testing.T) {
	_, user := BuildReplyDraftPrompt(ReplyDraftInput{
		AccountName:     "小安",
		PersonaBlock:    "直率科技人",
		ThreadPostText:  "今天來分享育兒心得",
		ParentReplyText: "我覺得放鬆最重要",
		ReplyText:       "@小安 你覺得呢？",
		ReplyToID:       "999",
	})
	for _, want := range []string{
		"【2. 主串貼文】", "今天來分享育兒心得",
		"【3. 上層留言】", "我覺得放鬆最重要",
		"【4. 對方 @ 你的內容】", "@小安 你覺得呢？",
	} {
		if !strings.Contains(user, want) {
			t.Fatalf("missing %q in mention user prompt:\n%s", want, user)
		}
	}
}

func TestNormalizeHumanReplyStripsQuotesAndBreaksLines(t *testing.T) {
	got := NormalizeHumanReply(`"第一段真的超累到不想講話。第二段後來洗個澡就還好一點。第三段你加油，我們一起撐過這週。"`)
	if strings.HasPrefix(got, `"`) {
		t.Fatalf("expected quotes stripped, got %q", got)
	}
	if !strings.Contains(got, "\n") {
		t.Fatalf("expected line breaks, got %q", got)
	}
}
