package worker

import "testing"

func TestValidateScriptAnalysisResult(t *testing.T) {
	var result scriptAnalysisResult
	result.SellingPoint.Summary = "核心卖点"
	result.StoryStructure.Synopsis = "剧情梗概"
	for episode := 1; episode <= 10; episode++ {
		result.EpisodeHooks = append(result.EpisodeHooks, scriptEpisodeHook{EpisodeNo: episode})
	}
	for index := 0; index < 3; index++ {
		result.Episode10PaywallHooks = append(result.Episode10PaywallHooks, scriptPaywallHook{Content: "候选"})
	}
	result.StoryStructure.Characters = []scriptAnalysisCharacter{{Name: "甲", Faction: "正派"}, {Name: "乙", Faction: "反派"}, {Name: "丙", Faction: "中立派"}}
	if err := validateScriptAnalysisResult(result); err != nil {
		t.Fatalf("expected valid analysis result: %v", err)
	}

	result.EpisodeHooks[9].EpisodeNo = 9
	if err := validateScriptAnalysisResult(result); err == nil {
		t.Fatal("expected invalid episode hook ordering")
	}
}

func TestValidateScriptAnalysisResultRejectsInvalidFaction(t *testing.T) {
	var result scriptAnalysisResult
	result.SellingPoint.Summary = "核心卖点"
	result.StoryStructure.Synopsis = "剧情梗概"
	for episode := 1; episode <= 10; episode++ {
		result.EpisodeHooks = append(result.EpisodeHooks, scriptEpisodeHook{EpisodeNo: episode})
	}
	result.Episode10PaywallHooks = make([]scriptPaywallHook, 3)
	result.StoryStructure.Characters = []scriptAnalysisCharacter{{Name: "甲", Faction: "未知"}}
	if err := validateScriptAnalysisResult(result); err == nil {
		t.Fatal("expected invalid character faction")
	}
}
