package placement

import (
	"strings"
)

// MemberCapabilities summarizes which external integrations are ready for the
// current member + active Threads operating account.
type MemberCapabilities struct {
	DiscoverReady        bool
	AiReady              bool
	PublishReady         bool
	DiscoverHint         string
	AiHint               string
	PublishHint          string
	ActiveThreadsAccount string
}

func BuildMemberCapabilities(member MemberContext, research ResearchSettings, aiReady, publishReady bool) MemberCapabilities {
	out := MemberCapabilities{
		DiscoverReady:        member.HasDiscoverPath(),
		AiReady:              aiReady,
		PublishReady:         publishReady,
		ActiveThreadsAccount: strings.TrimSpace(member.ActiveAccountID),
	}
	if !out.DiscoverReady {
		out.DiscoverHint = discoverCapabilityHint(member, research)
	}
	if !out.AiReady {
		out.AiHint = "請先在設定頁設定 AI API key"
	}
	if !out.PublishReady {
		out.PublishHint = publishCapabilityHint(member)
	}
	return out
}

func discoverCapabilityHint(member MemberContext, research ResearchSettings) string {
	if strings.TrimSpace(member.ActiveAccountID) == "" {
		return "請先建立並選定經營帳號"
	}
	return discoverMissingPathError(member).Error()
}

func publishCapabilityHint(member MemberContext) string {
	if strings.TrimSpace(member.ActiveAccountID) == "" {
		return "請先建立並選定經營帳號"
	}
	return "請先完成 Threads API 連線後再發布貼文"
}
