package ownpost

import "testing"

func TestParsePostFormulaOutputIncludesImprovementsAndTemplate(t *testing.T) {
	raw := `{
  "summary": "整體互動偏低，但開場有吸引力。",
  "wins": ["開場直接點痛點"],
  "improvements": ["問題：收尾沒有問句｜改善：最後加一句開放式提問引導留言"],
  "formula": "Hook→情境→觀點→互動問句",
  "post_template": "[痛點一句]\n[親身情境]\n[你的觀點]\n[問句收尾]",
  "hook_pattern": "先丟痛點再現身說法",
  "structure": "4 段，每段 1-2 句",
  "replication_tips": ["下次同主題先寫 Hook 再補故事"],
  "avoid": ["不要一次講太多資訊"]
}`
	review, err := ParsePostFormulaOutput(raw)
	if err != nil {
		t.Fatalf("parse: %v", err)
	}
	if len(review.Improvements) != 1 {
		t.Fatalf("improvements: got %d", len(review.Improvements))
	}
	if review.PostTemplate == "" {
		t.Fatal("expected post_template")
	}
}

func TestTrimStringListDropsEmpty(t *testing.T) {
	got := trimStringList([]string{" a ", "", "b"})
	if len(got) != 2 || got[0] != "a" || got[1] != "b" {
		t.Fatalf("unexpected: %#v", got)
	}
}
