package viral

import "testing"

func TestParseMissionResearchMapOutput_ObjectPillars(t *testing.T) {
	raw := `{
  "audienceSummary": "轉職焦慮的上班族",
  "contentGoal": "找近期高互動轉職心情貼文",
  "questions": ["轉職會後悔嗎", "被裁怎麼辦"],
  "pillars": [
    {"title": "語錄型", "description": "一句話戳中焦慮"},
    {"title": "故事型", "description": "親身轉職經驗"}
  ],
  "exclusions": ["純業配", "無結構閒聊"],
  "suggestedTags": [
    {"tag": "轉職焦慮", "reason": "近期熱詞", "searchIntent": "痛點", "searchType": "短詞"},
    {"tag": "被裁", "reason": "高互動", "searchIntent": "痛點", "searchType": "短詞"},
    {"tag": "面試失敗", "reason": "共鳴", "searchIntent": "經驗", "searchType": "情境"},
    {"tag": "裸辭", "reason": "討論多", "searchIntent": "語錄", "searchType": "短詞"}
  ],
  "benchmarkNotes": "互動高且 hook 清楚"
}`
	out, err := ParseMissionResearchMapOutput(raw)
	if err != nil {
		t.Fatalf("ParseMissionResearchMapOutput: %v", err)
	}
	if len(out.Pillars) < 2 {
		t.Fatalf("expected parsed pillars, got %#v", out.Pillars)
	}
	if out.Pillars[0] == "" {
		t.Fatal("first pillar should not be empty")
	}
	if len(out.SuggestedTags) < 4 {
		t.Fatalf("expected suggested tags, got %#v", out.SuggestedTags)
	}
}

func TestParseMissionResearchMapOutput_StringSuggestedTags(t *testing.T) {
	raw := `{
  "audienceSummary": "新手媽媽",
  "contentGoal": "找育兒爆款",
  "questions": ["哄睡", "副食品"],
  "pillars": ["清單型", "故事型", "語錄型", "問答型"],
  "exclusions": ["業配", "晒娃", "無重點", "抄襲"],
  "suggestedTags": ["哄睡", "副食品", "崩潰", "育兒"],
  "benchmarkNotes": "留言多"
}`
	out, err := ParseMissionResearchMapOutput(raw)
	if err != nil {
		t.Fatalf("ParseMissionResearchMapOutput: %v", err)
	}
	if len(out.SuggestedTags) != 4 {
		t.Fatalf("expected 4 tags, got %#v", out.SuggestedTags)
	}
}
