package session

import "github.com/tidbcloud/AgentTeam/desktop/internal/types"

// SessionsStore is the narrow read dependency for listing active sessions.
type SessionsStore interface {
	Sessions() []types.SessionSnapshot
}

// SessionLookupStore is the narrow read dependency for resolving one active session.
type SessionLookupStore interface {
	Session(agentID string) (types.SessionSnapshot, bool)
}

// SessionRestartStore is the narrow lifecycle dependency for refreshing one
// running leader runtime without clearing workspace state.
type SessionRestartStore interface {
	RestartByAgent(agentID string) bool
}

// SessionStore composes active-session lookup and listing capabilities.
// Individual session handlers should accept the narrower interfaces above.
type SessionStore interface {
	SessionsStore
	SessionLookupStore
}

// TrajectoryStreamStore is the dependency needed by the per-agent trajectory SSE endpoint.
type TrajectoryStreamStore interface {
	Session(agentID string) (types.SessionSnapshot, bool)
	SubscribeTrajectory(agentID string) <-chan types.TrajectoryLogItem
	SubscribeLiveTrajectory(agentID string) <-chan types.TrajectoryLogItem
	UnsubscribeTrajectory(agentID string, ch <-chan types.TrajectoryLogItem)
}

// TrajectoryHistoryStore is the dependency needed by the trajectory history endpoint.
type TrajectoryHistoryStore interface {
	TrajectoryHistory(agentID string, limit int, before int64) []types.TrajectoryLogItem
}

// TrajectoryLiveStore is the dependency needed by the all-agent live trajectory SSE endpoint.
type TrajectoryLiveStore interface {
	SubscribeAllLiveTrajectory() <-chan types.TrajectoryLogItem
	UnsubscribeAllTrajectory(ch <-chan types.TrajectoryLogItem)
}

// TrajectoryLatestStore is the dependency needed by the latest trajectory endpoint.
type TrajectoryLatestStore interface {
	Sessions() []types.SessionSnapshot
	LatestTrajectoryByAgent(agentIDs []string) map[string]types.TrajectoryLogItem
}

// TrajectoryStore composes the trajectory capabilities provided by the daemon.
// Individual handlers accept the narrower interfaces above.
type TrajectoryStore interface {
	TrajectoryStreamStore
	TrajectoryHistoryStore
	TrajectoryLiveStore
	TrajectoryLatestStore
}
