package viral

import "haixun-backend/internal/library/placement"

// Mission-quality gates for copy-mission viral patrol (stricter than generic patrol).
const (
	MissionQualityMinLikes        = 18
	MissionQualityMinEngagement   = 50
	MissionVerifiedMinLikes       = 10
	MissionVerifiedMinEngagement  = 35
	MissionInfluencerMinFollowers = 5000
)

// PassesMissionQualityCandidate filters copy-mission scan results toward higher-signal posts.
// AuthorVerified and FollowerCount are optional enrichments (often missing on Threads API);
// when absent the default engagement bar still applies — callers should fall back to
// PassesViralCandidate rather than treating empty optional signals as failure.
func PassesMissionQualityCandidate(text string, likes, replies, engagement int, verified bool, followerCount int, exclusions []string) bool {
	if !PassesViralCandidate(text, likes, replies, engagement, exclusions) {
		return false
	}
	if verified {
		return likes >= MissionVerifiedMinLikes && engagement >= MissionVerifiedMinEngagement
	}
	if followerCount >= MissionInfluencerMinFollowers {
		return likes >= 12 && engagement >= 40
	}
	return likes >= MissionQualityMinLikes && engagement >= MissionQualityMinEngagement
}

func MergeAuthorSignals(prev, next placement.ScanCandidate) placement.ScanCandidate {
	if next.AuthorVerified {
		prev.AuthorVerified = true
	}
	if next.FollowerCount > prev.FollowerCount {
		prev.FollowerCount = next.FollowerCount
	}
	return prev
}
