package handlers

// This file previously contained all tree traversal logic (path building,
// sibling queries, cursor management). As of v0.15.0, the core logic lives
// in the treepath package; these are package-local aliases so existing
// handler code (messages.go, completion.go) compiles with minimal churn.
//
// New code should import treepath directly.

import (
	"chat-switchboard/treepath"
)

// ── Type Aliases ────────────────────────────
// Existing handler code references these types by unqualified name.

type PathMessage = treepath.PathMessage
type SiblingInfo = treepath.SiblingInfo

// ── Function Wrappers ───────────────────────

func getActiveLeaf(channelID, userID string) (*string, error) {
	return treepath.GetActiveLeaf(channelID, userID)
}

func getActivePath(channelID, userID string) ([]PathMessage, error) {
	return treepath.GetActivePath(channelID, userID)
}

func getPathToLeaf(channelID, leafID string) ([]PathMessage, error) {
	return treepath.GetPathToLeaf(channelID, leafID)
}

func getSiblingCount(channelID string, parentID *string) int {
	return treepath.GetSiblingCount(channelID, parentID)
}

func getSiblings(messageID string) ([]SiblingInfo, int, error) {
	return treepath.GetSiblings(messageID)
}

func findLeafFromMessage(messageID string) (string, error) {
	return treepath.FindLeafFromMessage(messageID)
}

func nextSiblingIndex(channelID string, parentID *string) int {
	return treepath.NextSiblingIndex(channelID, parentID)
}

func updateCursor(channelID, userID, messageID string) error {
	return treepath.UpdateCursor(channelID, userID, messageID)
}

// isSummaryMessage checks if a PathMessage has summary metadata.
// This was previously defined in completion.go; moved here alongside the
// other tree helpers so all callers use the canonical treepath version.
func isSummaryMessage(m *PathMessage) bool {
	return treepath.IsSummaryMessage(m)
}
