package outreach

import "testing"

func TestParseGenerateOutput(t *testing.T) {
	raw := `{"relevance":0.85,"reason":"對方在問敏感肌保養","drafts":[{"text":"我之前也這樣…","angle":"共情","rationale":"先回應情緒"}]}`
	got, err := ParseGenerateOutput(raw)
	if err != nil {
		t.Fatalf("ParseGenerateOutput() error = %v", err)
	}
	if got.Relevance != 0.85 {
		t.Fatalf("relevance = %v, want 0.85", got.Relevance)
	}
	if len(got.Drafts) != 1 || got.Drafts[0].Text == "" {
		t.Fatalf("drafts = %+v", got.Drafts)
	}
}

func TestParseGenerateOutputCodeFence(t *testing.T) {
	raw := "```json\n{\"relevance\":1.2,\"reason\":\"ok\",\"drafts\":[{\"text\":\"hi\",\"angle\":\"a\",\"rationale\":\"b\"}]}\n```"
	got, err := ParseGenerateOutput(raw)
	if err != nil {
		t.Fatalf("ParseGenerateOutput() error = %v", err)
	}
	if got.Relevance != 1 {
		t.Fatalf("relevance clamped = %v, want 1", got.Relevance)
	}
}
